簡體   English   中英

無法將文件保存在Linux服務器上運行的tomcat Webapp中

[英]Can't save file in tomcat webapp running on a linux server

我目前正在調試一個webapp ,用戶應該在其中上載一個文件,然后將該文件臨時存儲在服務器上並通過電子郵件發送給管理員。

該應用程序在Linux服務器環境中的tomcat 8上運行。 發生錯誤的類如下所示:

@Service
public class BugReportBo implements IBugReportBo {

  ...

  @Value("${app.temp.folder}")
  private Resource temp;

  ...

  private File byteArrayToFile(final byte[] lob, final String string) throws IOException {
    final int locatorStartPos = 6;
    String uri = temp.getURI().toString().substring(locatorStartPos);

    //uri: var/lib/tomcat/webapps/prototype/res/temp/
    //string: temp0.jpg

    // convert array of bytes into file
    File f = new File(uri + string);
    FileOutputStream fileOuputStream = new FileOutputStream(uri + string);
    fileOuputStream.write(lob);
    fileOuputStream.close();
    return f;
  }
}

FileOutputStream fileOuputStream = new FileOutputStream(uri + string);拋出錯誤FileOutputStream fileOuputStream = new FileOutputStream(uri + string);

異常是FileNotFoundException (消息:“ var / lib / tomcat / webapps / prototype / res / temp / temp0.jpg(日期或日期))”。

一切似乎對我來說還可以,因為該文件夾應該在該文件夾中,並且路徑似乎也不錯。

有任何想法嗎?

var / lib / tomcat / webapps / prototype / res / temp / temp0.jpg

您會忘記第一個“ /”,因此該路徑像相對路徑一樣被理解,而不是絕對路徑。

/var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM