0
私は自分のコンピュータ上でPDFファイルを選択できるhtmlフォームから呼び出されたサーブレットの "File"インスタンスを取得しようとしています。 "InputStream"としてファイルを取得できましたが、それを "File"オブジェクトに変換することはできません。InputStreamオブジェクトをFileオブジェクトに変換するにはどうすればよいですか?
いろいろ試してみたら、私はまだそれを動作させるために何をすべきか理解できません。何か案が ?
エラー:
java.io.FileNotFoundException: test.pdf (Read-only file system)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:360)
at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:319)
at org.apache.commons.io.FileUtils.copyToFile(FileUtils.java:1552)
at org.apache.commons.io.FileUtils.copyInputStreamToFile(FileUtils.java:1528)
コード:
Part filePart = request.getPart("file");
InputStream fileContent = filePart.getInputStream();
if (fileContent != null)
{
File file = new File(filename.trim() + ".pdf");
FileUtils.copyInputStreamToFile(fileContent, file);
//use the "file" instance
//...
}