作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 Java 从 Amazon 文件路径获取文件。它总是返回(文件名、目录名或卷标语法不正确)错误。如果我给出本地路径,它就可以完美工作。这是我的代码
FileInputStream fis;
String filePath = "https://mydomain:8080/S3DOC/?filename=/folder/DEV/Portal/sample.doc";
if(FilePath.substring(FilePath.length() -1).equals("x")){ //is a docx
System.out.println("docx");
try {
fis = new FileInputStream(new File(FilePath));
XWPFDocument doc = new XWPFDocument(fis);
XWPFWordExtractor extract = new XWPFWordExtractor(doc);
System.out.println(extract.getText());
} catch (IOException e) {
e.printStackTrace();
}
} else { //is not a docx
System.out.println("doc");
try {
fis = new FileInputStream(new File(FilePath));
HWPFDocument doc = new HWPFDocument(fis);
WordExtractor extractor = new WordExtractor(doc);
System.out.println(extractor.getText());
} catch (IOException e) {
e.printStackTrace();
}
}
错误:java.io.FileNotFoundException:https:\mydomain:8080\S3DOC\?filename=\folder\DEV\Portal\sample.doc(文件名、目录名或卷标语法不正确)
最佳答案
s3路径如:s3://bucket/key
您可以使用
AmazonS3Client.getObject(String bucketName, String key);
获取S3Object,然后获取InputStream。
关于java - 如何从 S3 链接获取文件 - java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055951/
我是一名优秀的程序员,十分优秀!