0

プロジェクトの相対パスにファイルをアップロードしたいと考えています。

webapp/fileUpload/ は、ファイルをアップロードするパスです。

だから私がパスを与えるとき

 CommonsMultipartFile commonsFile = user.getImage();
 String fileName = commonsFile.getOriginalFilename();

 File destFile = new File("http://localhost:8080/SpringDemo/fileUpload/",fileName);

それは私に与えます

java.io.FileNotFoundException: http:\localhost:8080\SpringDemo\fileUpload\design.txt(The filename, directory name, or volume label syntax is incorrect)

何が正しい道なのか理解できません。

I want to save it under my project folder and not on any other path so I am using  http:\localhost:8080\SpringDemo\fileUpload\as the path.

When i paste http://localhost:8080/SpringDemo/fileUpload/abc.txt into my browser it shows me the file.(abc.txt)

何が正しい道なのか理解できません。

これを行う正しい方法を教えてください。

前もって感謝します。

ジンゴ

4

2 に答える 2

0

まず、コンテキスト内で保存したファイルは、アプリをアンデプロイすると失われるため、それが必要であることを確認してください。

あなたの質問に関してhttp://localhost/etc/and/so/onは、ファイル パスではなく、アプリの URL です。

ファイル パスは、基になるファイル システムの実際のパスです。

/usr/share にインストールされている Tomcat を使用しているとします。アプリ内のファイル パスは次のようになります。/usr/share/tomcat/webapps/yourapp/somewhere/you/want/files/stored/some-file.txt

于 2013-04-20T05:12:15.867 に答える