标签:
编写IoDemo.java的Java应用程序,程序完成的功能是:首先读取text.txt文件内容,再通过键盘输入文件的名称为iodemo.txt,把text.txt的内容存入iodemo.txt
package com.hanqi.test; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class IoDemo { public static void main(String[] args) { try { FileInputStream in = new FileInputStream("d:/text.txt"); byte [] b= new byte[1024]; int i =-1; FileOutputStream out = new FileOutputStream("d:/IoDemo.txt"); while((i=in.read(b))>0) { out.write(b,0,i); } out.close(); in.close(); System.out.println("存入成功"); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }
标签:
原文地址:http://www.cnblogs.com/wangguoning/p/5912527.html