2013-07-18 29 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);
}

参数文件,它必须删除,然后它的工作!