如何从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(文件名,目录名或卷标语法不正确)
答案 0 :(得分:1)
s3路径如:s3:// bucket / key
您可以使用
AmazonS3Client.getObject(String bucketName, String key);
获取S3Object,然后获取InputStream。