質問編集履歴
2
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,7 +120,7 @@
|
|
120
120
|
|
121
121
|
File file = new File(filePath);
|
122
122
|
|
123
|
-
FileInputStream in = new FileInputStream(file); //エラー
|
123
|
+
FileInputStream fileInputStream = new FileInputStream(file); //エラー
|
124
124
|
|
125
125
|
|
126
126
|
|
1
質問変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,24 +22,118 @@
|
|
22
22
|
|
23
23
|
FileNotFoundExceptionになってしまいます。
|
24
24
|
|
25
|
-
|
25
|
+
```java
|
26
26
|
|
27
27
|
File file = new File(filePath);
|
28
28
|
|
29
|
-
|
29
|
+
```
|
30
30
|
|
31
31
|
を
|
32
32
|
|
33
|
-
|
33
|
+
```java
|
34
34
|
|
35
35
|
FileInputStream fileInputStream = new FileInputStream(file);
|
36
36
|
|
37
|
+
```
|
37
38
|
|
38
|
-
|
39
|
-
としてい
|
39
|
+
としていおります。
|
40
|
-
|
41
|
-
変換の方法が間違っているのでしょか?
|
42
40
|
|
43
41
|
|
44
42
|
|
43
|
+
filePathは下記のような値になっております。
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
/ワークスペース/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/プロジェクト名/格納するパス名/ファイル名
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
jspでsubmitした時のスタックトレースを記載いたします。
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
java.io.FileNotFoundException: 上記のパス (No such file or directory)
|
58
|
+
|
59
|
+
at java.io.FileInputStream.open(Native Method)
|
60
|
+
|
61
|
+
at java.io.FileInputStream.<init>(FileInputStream.java:138)
|
62
|
+
|
63
|
+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
|
64
|
+
|
65
|
+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
|
66
|
+
|
67
|
+
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
|
68
|
+
|
69
|
+
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
|
70
|
+
|
71
|
+
以下省略
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
また、サーブレット側のソースコードを記載いたします。
|
78
|
+
|
79
|
+
```java
|
80
|
+
|
81
|
+
String path = getServletContext().getRealPath("files");
|
82
|
+
|
83
|
+
DiskFileItemFactory factory = new DiskFileItemFactory();
|
84
|
+
|
85
|
+
ServletFileUpload upload = new ServletFileUpload(factory);
|
86
|
+
|
87
|
+
factory.setSizeThreshold(1024);
|
88
|
+
|
89
|
+
upload.setSizeMax(4000 * 1024);
|
90
|
+
|
91
|
+
upload.setFileSizeMax(3000 * 1024);
|
92
|
+
|
93
|
+
upload.setHeaderEncoding("UTF-8");
|
94
|
+
|
95
|
+
try {
|
96
|
+
|
97
|
+
List list = upload.parseRequest(request);
|
98
|
+
|
99
|
+
Iterator iterator = list.iterator();
|
100
|
+
|
101
|
+
while (iterator.hasNext()) {
|
102
|
+
|
103
|
+
FileItem fItem = (FileItem) iterator.next();
|
104
|
+
|
105
|
+
if (!(fItem.isFormField())) {
|
106
|
+
|
107
|
+
fileName = fItem.getName();
|
108
|
+
|
109
|
+
long size = fItem.getSize();
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
if ((fileName != null) && (!fileName.equals(""))) {
|
114
|
+
|
115
|
+
String fileName2 = (new File(fileName)).getName();
|
116
|
+
|
117
|
+
filePath = path + "/" + fileName;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
File file = new File(filePath);
|
122
|
+
|
123
|
+
FileInputStream in = new FileInputStream(file); //エラー
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
in.close();
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
...
|
136
|
+
|
137
|
+
```
|
138
|
+
|
45
139
|
皆様のお力添えのほど、よろしくお願い致します。
|