1 ////////////////////////////////////////////////////////////////
 2 //  
 3 //  程序:ReadWiteFile.java
 4 //
 5 //  描述:对文件读写操作
 6 //
 7 //  作者:JAVA-HE
 8 //
 9 //  时间: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 ("读文件发生异常:"+ex.toString ());
34         }
35         try
36         {
37             managerFile.writeFile(writefile,content);
38         }catch(Exception e)
39         {
40             System.out.println ("写文件发生异常:"+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 阅读(499) 评论(0)  编辑  收藏 所属分类: JAVA

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(21)

随笔分类(265)

随笔档案(242)

相册

JAVA网站

关注的Blog

搜索

  •  

积分与排名

  • 积分 - 908981
  • 排名 - 40

最新评论