java复制单个文件 FileInputStream
2015-09-15 16:02
591 查看
public class CopydocumentTest {
public static void main(String[] args) {
String oldPath="C:\\dd\\dd.doc";
String newPath="C:\\dd\\ddcopy.doc";
try {
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
FileInputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1024];
int length;
while ( (length = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, length);
}
inStream.close();
}
}
catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();
}
}
}
public static void main(String[] args) {
String oldPath="C:\\dd\\dd.doc";
String newPath="C:\\dd\\ddcopy.doc";
try {
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
FileInputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1024];
int length;
while ( (length = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, length);
}
inStream.close();
}
}
catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();
}
}
}
相关文章推荐
- 深入理解Java Proxy机制
- spring整合hibernate
- JAVA基础之理解JNI原理
- java笔记——初学面向对象06
- NetBeans的快捷键使用汇总
- Java中各Set实现类的性能分析
- JAVA EE企业级开发四步走完全攻略
- java对象的交互
- java学习之List集合
- 【Java基础】--算法与数组
- spring mvc学习(一)
- JAVA中如何使用log4j作为日志记录工具
- Spring MVC基于注解的Controller
- javax.servlet.jsp.JspException cannot be resolved to a type
- 用 java 写一个计算器
- java.util.concurrent 学习笔记(1)
- JDK环境变量配置
- Maven学习记录5——Eclipse添加maven依赖找不到maven库中的jar
- javac 编译
- 【leetcode】ZigZag Conversion【java】