java 大文件copy疑义
java 大文件copy疑问
项目中需要对大文件(1G,2G... .)进行copy,从A服务器(windows )copy到B服务器(linux ).
使用java.io下的BufferedInputStream,BufferedOutputStream来完成。却发现需要2,3个小时才能完成1G文件copy。
为啥需要这么久呢? 两台服务器都在同一个域下。
或者说。。 哪位前辈有这方面的经验。。 期待分享。。。。。。
private static int BUFFER_SIZE=8*1024;
public static void copyFile(String resourcesPath,String targetPath) throws IOException{ File resourcesFile = new File(resourcesPath); File targetFile = new File(targetPath); BufferedInputStream input = new BufferedInputStream(new FileInputStream(resourcesFile)); BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(targetFile)); try { byte[] buffer = new byte[BUFFER_SIZE]; int n = 0; while (-1 != (n = input.read(buffer, 0, BUFFER_SIZE ))) { output.write(buffer, 0, n); output.flush(); } } finally { if(input!=null){ input.close(); } if (output != null) { output.close(); } } }
output.flush();
放到while中和放到while外应该没有太大的区别把。。。。?