java 对文本的写和读

 

-----------写操作

File   file=new   File(request.getRealPath("/")+File.separatorChar+"common"+File.separatorChar+"tbcdecmptype.txt");   
   System.out.println(request.getRealPath("/")+File.separatorChar+"common"+File.separatorChar+"tbcdecmptype.txt");
    FileWriter   outtemp=new   FileWriter(file);   
    outtemp.write(outString);   
    outtemp.close();   

  -----读操作


   FileReader reader = new FileReader(request.getRealPath("/")+"common"+File.separatorChar+"tbcdecmptype.txt");    
       BufferedReader br = new BufferedReader(reader);    
       String s1 = null;    
       while((s1 = br.readLine()) != null) {    
        outString=s1;
       }    
      br.close();    
      reader.close();    

 

你可能感兴趣的:(java)