zoukankan      html  css  js  c++  java
  • Java 文件读写示例1

    //StringBuffer常用于字符串追加,插入,删除

    import java.io.*;

    public class IOFile {
     static File f=new File("test.txt");
     static int count=0;
     public static void main(String[] args)
     {
      if(!f.exists())
      {
       try
       {
       f.createNewFile();
       }catch(IOException e1)
       {
        System.out.println(e1);
       }catch(Exception e2){
        System.out.println(e2);
       }
      }
       for(int i=0;i<5;i++)
       {
      try
      {
      FileWriter fos=new FileWriter(f,true);
      fos.write(String.valueOf(i));
      fos.write(' ');
      fos.flush();
      fos.close();
      }catch(FileNotFoundException e)
      {
       System.out.println(e);
      }catch(IOException e1)
      {
       System.out.println(e1);
      }
       }
      try
      {
       BufferedReader br=new BufferedReader(new FileReader("test.txt"));
       String str=null;
       for(str=br.readLine();str!=null;str=br.readLine())
        System.out.println(str);
       br.close();
       
      }catch(FileNotFoundException e1)
      {
       System.out.println(e1);
      }catch(IOException e2)
      {
       System.out.println(e2);
      }
      
     }

    }

  • 相关阅读:
    四种常用正则表达式
    解读tomcat的server.xml文件
    存储过程与函数的区别
    Servlet如何处理一个请求?
    Oracle归档模式相关
    常用几个Struts2标签
    Js中比较时间大小
    传值出现中文乱码问题
    JAVA常用转义符
    HDU 5967(LCT)
  • 原文地址:https://www.cnblogs.com/HackHer/p/5005216.html
Copyright © 2011-2022 走看看