Java的IO流操作

    技术2022-06-29  80

    《《《《《《Java的IO流操作》》》》》》》

    package IO流; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.Date;

     public class ioText {             /*              *@auther 何桂坤 2010-8-26              */  public static void main(String[] args) {   try{    //获取存在的文件    File file = new File("f://心事小写/生日小写.txt");//获得文本文件生日小写.txt    FileInputStream inputStream = new FileInputStream(file);//实例化输入流    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);//创建读取文件流    BufferedReader br = new BufferedReader(inputStreamReader);//读取文件流    //---------------------    //实例化空文本文件               Date time=new Date();//间               SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");               String t=format.format(time);//在文件名前加上时间    FileOutputStream outputStream = new FileOutputStream("f://IO流测试/"+t+file.getName());//用原来的 文件名作为新的文件名    OutputStreamWriter owp = new OutputStreamWriter(outputStream);//创建写出流    //------------------owp-----    String s = null;    while((s=br.readLine())!=null){     System.out.println(s);     owp.write("/r/n"+s);///r/n为换行      }    SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");    owp.write("/r/n/r/n"+format2.format(time)+"执笔而写");    owp.flush();    owp.close();    br.close();    inputStreamReader.close();   }catch(Exception e){    e.printStackTrace();   }  }

     }

         //代码来自heguikun个人网站


    最新回复(0)