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
//...
}