public class TestIO {
public static void main(String[] args) {
File inputFile = new File("a.txt");//这个地方要考虑到a.txt和b.txt在项目中的位置
File outputFile = new File("b.txt");

//b.txt文件不存在,可以创建
if(outputFile.exists()){

}else{
try {
outputFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

InputStream inputStream = null;
OutputStream outputStream = null;
int temp;
try {
inputStream = new FileInputStream(inputFile);
outputStream = new FileOutputStream(outputFile);
//读取a.txt数据并写到b.txt文件中
while((temp = inputStream.read()) != -1){
outputStream.write(temp);
}
} catch (FileNotFoundException e) {

e.printStackTrace();
Runtime.getRuntime().exit(-1);
} catch(IOException e){
e.printStackTrace();
} finally{
try{
//一定要关闭,否则可能得不到结果
inputStream.close();
outputStream.close();
}catch(Exception e){
e.printStackTrace();
}
}

}
}

最新文章

  1. 安装opensuse时遇到的一些问题
  2. PHP基础面试题
  3. 【逐步完善】MySql索引相关
  4. 【转】Wireshark:“There are no interfaces on which a capture can be done ”
  5. codeforces 333B - Chips
  6. 《深度探索c++对象模型》chapter1关于对象对象模型
  7. 山东省赛J题:Contest Print Server
  8. linux 防火墙开端口(转)
  9. Java设计模式--Java Builder模式
  10. 使用mybatis插入自增主键ID的数据后返回自增的ID
  11. 10个技巧优化PHP程序Laravel 5框架
  12. beego框架的最简单登入演示
  13. bootstrap 解决弹出窗口(modal) 常见问题
  14. HTML5 full-screen全屏API
  15. Itween 动画插件中 的画线
  16. Java-jacob-文件转HTML
  17. win10 + VS2015 + 64位OSG3.4.0
  18. ES6基础一
  19. 仿饿了么增加购物车旋转控件 - 自带闪转腾挪动画 的button
  20. nginx / apache / tomcat /resin等 http server的benchmark性能测试方法

热门文章

  1. Linux下CMake使用介绍
  2. 【bzoj1028】[JSOI2007]麻将
  3. luogu 3415 祭坛
  4. pandas删除满足特定列信息的行记录
  5. PCB javascript解析钻孔(Excellon)格式实现方法
  6. go多进程
  7. 原生方式实现Ajax技术
  8. 2019 年了,为什么我还在用 jQuery?
  9. 34、JavaScript面向对象(内置构造函数&相关方法|属性|运算符&继承&面向对象)
  10. .net 必看书籍1