1 ////////////////////////////////////////////////////////////////
           2 //  
           3 //  程序:ReadWiteFile.java
           4 //
           5 //  描述:對文件讀寫操作
           6 //
           7 //  作者:JAVA-HE
           8 //
           9 //  時(shí)間:2006-12-20
          10 //
          11 //////////////////////////////////////////////////////////////
          12 
          13 package com.readwritefile;
          14 
          15 import java.io.*;
          16 public class ReadWiteFile
          17 {
          18     public ReadWiteFile ()
          19     {
          20     }
          21     public static void main(String args [])
          22     {
          23         ReadWiteFile managerFile = new ReadWiteFile();
          24         File readfile = new File("read.txt");
          25         File writefile = new File("write.txt");
          26         String content = "";
          27         try
          28         {
          29             content = managerFile.readFile(readfile);
          30             
          31         }catch(Exception ex)
          32         {
          33             System.out.println ("讀文件發(fā)生異常:"+ex.toString ());
          34         }
          35         try
          36         {
          37             managerFile.writeFile(writefile,content);
          38         }catch(Exception e)
          39         {
          40             System.out.println ("寫文件發(fā)生異常:"+e.toString ());
          41         }
          42     }
          43     private  String readFile (File readfile) throws Exception 
          44     {
          45         FileReader read = new FileReader(readfile);
          46         BufferedReader in = new BufferedReader(read);
          47         String readResult="";
          48         String str = "";
          49         while((str=in.readLine ())!= null)
          50         {
          51             String tem [] = str.split ("=");
          52             readResult += "m_objCitys.Add \""+tem[1]+"\", \""+tem[0]+"\""+"\n";
          53         }
          54         read.close ();
          55         in.close ();
          56         return readResult;
          57     }
          58 
          59     private void writeFile (File writefile, String content) throws Exception
          60     {
          61         FileWriter write = new FileWriter(writefile);
          62         BufferedWriter wr = new BufferedWriter(write);
          63         wr.write (content);
          64         wr.flush ();
          65         wr.close ();
          66         write.close ();
          67     }
          68     
          69 }
          70 
          71 
          72 
          73 
          74 

          posted on 2007-02-13 14:45 -274°C 閱讀(526) 評論(0)  編輯  收藏 所屬分類: JAVA

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網(wǎng)站

          關(guān)注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 917238
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 景宁| 临沂市| 遂平县| 舞阳县| 敦煌市| 司法| 根河市| 吉林市| 县级市| 九台市| 吉林省| 京山县| 桂东县| 十堰市| 连城县| 高台县| 余姚市| 五大连池市| 集安市| 视频| 乌拉特后旗| 吴桥县| 鄂伦春自治旗| 北流市| 隆子县| 大埔县| 安乡县| 句容市| 衡水市| 南充市| 灵石县| 壶关县| 安仁县| 页游| 肇源县| 淳化县| 阿荣旗| 新干县| 大悟县| 云南省| 普兰县|