質問編集履歴
2
変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,7 +59,7 @@
|
|
59
59
|
filePath = path + "/" + fileName;
|
60
60
|
|
61
61
|
File file = new File(filePath);
|
62
|
-
FileInputStream
|
62
|
+
FileInputStream fileInputStream = new FileInputStream(file); //エラー
|
63
63
|
|
64
64
|
in.close();
|
65
65
|
}
|
1
質問変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,14 +10,61 @@
|
|
10
10
|
|
11
11
|
その後にFileInputStreamでファイルをバイト配列にしたいのですが、
|
12
12
|
FileNotFoundExceptionになってしまいます。
|
13
|
-
|
13
|
+
```java
|
14
14
|
File file = new File(filePath);
|
15
|
-
|
15
|
+
```
|
16
16
|
を
|
17
|
-
|
17
|
+
```java
|
18
18
|
FileInputStream fileInputStream = new FileInputStream(file);
|
19
|
+
```
|
20
|
+
としていおります。
|
19
21
|
|
20
|
-
としているのですが、
|
21
|
-
|
22
|
+
filePathは下記のような値になっております。
|
23
|
+
```
|
24
|
+
/ワークスペース/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/プロジェクト名/格納するパス名/ファイル名
|
25
|
+
```
|
22
26
|
|
27
|
+
jspでsubmitした時のスタックトレースを記載いたします。
|
28
|
+
```
|
29
|
+
java.io.FileNotFoundException: 上記のパス (No such file or directory)
|
30
|
+
at java.io.FileInputStream.open(Native Method)
|
31
|
+
at java.io.FileInputStream.<init>(FileInputStream.java:138)
|
32
|
+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
|
33
|
+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
|
34
|
+
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
|
35
|
+
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
|
36
|
+
以下省略
|
37
|
+
```
|
38
|
+
|
39
|
+
また、サーブレット側のソースコードを記載いたします。
|
40
|
+
```java
|
41
|
+
String path = getServletContext().getRealPath("files");
|
42
|
+
DiskFileItemFactory factory = new DiskFileItemFactory();
|
43
|
+
ServletFileUpload upload = new ServletFileUpload(factory);
|
44
|
+
factory.setSizeThreshold(1024);
|
45
|
+
upload.setSizeMax(4000 * 1024);
|
46
|
+
upload.setFileSizeMax(3000 * 1024);
|
47
|
+
upload.setHeaderEncoding("UTF-8");
|
48
|
+
try {
|
49
|
+
List list = upload.parseRequest(request);
|
50
|
+
Iterator iterator = list.iterator();
|
51
|
+
while (iterator.hasNext()) {
|
52
|
+
FileItem fItem = (FileItem) iterator.next();
|
53
|
+
if (!(fItem.isFormField())) {
|
54
|
+
fileName = fItem.getName();
|
55
|
+
long size = fItem.getSize();
|
56
|
+
|
57
|
+
if ((fileName != null) && (!fileName.equals(""))) {
|
58
|
+
String fileName2 = (new File(fileName)).getName();
|
59
|
+
filePath = path + "/" + fileName;
|
60
|
+
|
61
|
+
File file = new File(filePath);
|
62
|
+
FileInputStream in = new FileInputStream(file); //エラー
|
63
|
+
|
64
|
+
in.close();
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
...
|
69
|
+
```
|
23
70
|
皆様のお力添えのほど、よろしくお願い致します。
|