0
我有想用FileOutputStream中寫一個文件的應用流關閉顯示播放框架1.2.5起來
這裏的代碼,法補丁
public static Response patch() {
try {
System.out.println("PATCH");
System.out.println(request.contentType);
String file = params.get("filename");
System.out.println("patch file: " + file);
Map<String, Header> MapOffset = request.headers;
for (Entry<String, Header> entry : MapOffset.entrySet()) {
System.out.println("Header['" + entry.getKey() + "]: "
+ entry.getValue().value());
}
Header offsetParam = MapOffset.get("offset");
Long offset = 0L;
if (offsetParam != null) {
offset = Long.parseLong(offsetParam.value());
}
InputStream input = request.body;
File f = new File(UPLOAD_DIR + System.getProperty("file.separator")
+ file);
System.out.println("address: " + f.getAbsolutePath());
System.out.println("offset: " + offset);
System.out.println("length: " + f.length());
fileBasicUpload(f, offset, input);
Response respon = new Response();
respon.status = OK;
return respon;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
,這是我在哪裏寫一個文件
private static void fileBasicUpload(File f, Long offset, InputStream input)
throws IOException {
FileOutputStream output = null;
try {
int c = -1;
byte[] b = new byte[1024];
try {
output = new FileOutputStream(f, true);
while ((c = input.read(b)) != -1) {
output.write(b, 0, c);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
} finally {
output.close();
}
}
但叫我的應用程序時,則流封閉誤差顯示ü p在while ((c = input.read(b)) != -1)
那一行。 我不知道如何調用這個錯誤。對不起,我可憐的英語和謝謝
爲什麼不簡單使用'play.libs.IO.write(InuptStream,File)'方法或Apache Commons IO中的某個方法。它應該工作得很好,你會有更少的代碼行來修補以後:) –
我不知道有這樣的lib在播放,也許我應該試試:) – Yusuf1494
我已經嘗試過它,它仍然流關閉錯誤:( – Yusuf1494