我目前正在编写一个Web服务,它将图像存储在我的glassfish服务器实例上的目录中。出于某种原因,当从客户端使用Web服务时,它表示找不到目录或文件。我将一个字节数组传递给该方法。以下是我的代码:
@WebMethod(operationName="upload")
public String upload(String fileName, byte[] imageBytes){
String filePath = "/bucketlister/images/feature pictures/"+fileName;
try{
FileOutputStream fos = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(imageBytes);
bos.close();
return "Received file:" + filePath;
}catch(IOException e){
throw new WebServiceException(e);
}
}
FileOutputStream抛出FileNotFoundException。有任何想法吗?我更喜欢使用字节数组,但我愿意接受其他建议。
答案 0 :(得分:0)
我猜答案一直盯着我看..文件路径只指向目录的一半。它应该已经消失了
String filePath ="home/user/glassfish4/domains/domain1/bucketlister/images/feature_picture/" + fileName;
我不知道它是否有任何改变,但我将“feature picture”目录更改为“feature_picture”