2016-10-18 66 views
0

我目前正在寫的是關於我的GlassFish服務器實例的目錄存儲圖像的Web服務的GlassFish。出於某種原因,當Web服務從客戶端被使用時,它表示該目錄或文件未找到。我將一個字節數組傳遞給該方法。以下是我的代碼:保存圖像上使用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

你檢查的文檔?具體而言,> [* FileNotFoundException異常 - 如果該文件存在,但是一個目錄,而不是一個常規文件,不存在,但不能被創建,或不能打開任何其他原因*](https://docs.oracle.com/ JavaSE的/ 7 /文檔/ API/JAVA/IO/FileOutputStream.html)的更多細節將異常或問題,將有助於 –

+0

@NickBell它說,在'filePath' –

+0

,是相對路徑還是絕對路徑?如果它應該是相對的,那麼它被解釋爲絕對的。 – Mike

回答

0

我想答案是盯着我所有的同時..文件路徑是指向只有一半的目錄。它應該去

String filePath ="home/user/glassfish4/domains/domain1/bucketlister/images/feature_picture/" + fileName; 

我不知道這是否改變什麼,但我改變了「特色圖片」目錄「feature_picture」

相關問題