2013-07-18 59 views
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)那一行。 我不知道如何調用這個錯誤。對不起,我可憐的英語和謝謝

+0

爲什麼不簡單使用'play.libs.IO.write(InuptStream,File)'方法或Apache Commons IO中的某個方法。它應該工作得很好,你會有更少的代碼行來修補以後:) –

+0

我不知道有這樣的lib在播放,也許我應該試試:) – Yusuf1494

+0

我已經嘗試過它,它仍然流關閉錯誤:( – Yusuf1494

回答

0

我找到了答案。在我的應用程序中,我發現像這樣

public static Response upload(File file){ 
    System.out.println("Appliaction.upload"); 
    response = ResumableUpload.post(); 
    return response; 

// render(response);
}

參數文件,它必須刪除,然後它的工作!