java复制文件
2015-07-10 10:05
441 查看
// 测试复制文件 @Test public void copyFile() throws Exception { String srcPath="D:/qqqq.jpg"; String destPath="D:/copyqqqq.jpg"; InputStream input=null; File srcFile=new File(srcPath); if(srcFile.exists()){ input = new FileInputStream(srcFile); writeToLocal(input, destPath); } else{ System.out.println("文件不存在........"); return; } } public static void writeToLocal(InputStream in, String destPath) { FileOutputStream out = null; int b = 0; try { out = new FileOutputStream(destPath); while ((b = in.read()) != -1) { out.write(b); } } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- Java multi-threads to read DB then writting to local disk with Producer & Consumer model
- 二维码QRCode
- Java线程(七):Callable和Future
- Java线程(五):Timer和TimerTask
- Java线程(六):线程池
- eclipse创建android项目无法正常预览布局文件
- Java线程(三):线程协作-生产者/消费者问题
- Java9的一些新特性介绍
- Java线程(二):线程同步synchronized和volatile
- Java线程(一):线程安全与不安全
- java
- Eclipse -- An API baseline has not been set for the current workspace
- Eclipse设置完整的Java代码提示
- “黑马程序员” JDK怎么安装与配置环境变量
- 深入JVM剖析Java的线程堆栈
- Java Network Programming with Callback model
- jdk阅读xml文件
- java web 拦截器与过滤器区别
- JAVA入门基础笔记--string类型
- JAVA入门基础笔记-数组类型