<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> 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
分享到:
相关推荐
有时候需要在Linux kernel--大多是在需要调试的驱动程序--中读写文件数据。在kernel中操作文件没有标准库可用,需要利用kernel的一些函数,这些函数主要有:filp_open() filp_close(), vfs_read() vfs_write(),set_...
通过can总线实现对U盘拔插的感应以及在U盘中读写文件,并在oled上显示状态。包括整个工程文件。 U盘读写文件程序\YT32B1_STM32F103_demo.uvproj, 19771 , 2018-04-27 U盘读写文件程序\Basic\adc\adc.c, 4288 , 2018...
js实现的读写文件,文件放在的c:\12.txt里
Android 读写文件实例,包括 SD 卡读写和 内部存储读写。 文件目录获取等。
Android JNI Android JNI 用C函数写本地库读写文件,底层调用小例子用C函数写本地库读写文件,底层调用小例子
使用systemverilog进行读写文件操作,实现读文件数据和写文件数据。
用CFile类简单读写文件
Android studio 获取内置存储器路径,创建文件夹,读写、删除文件,亲试好用
用于读写文件的类,比较方便!
文件读写 文件读写文件读写 文件读写文件读写 文件读写
在编程总经常会用到读写文件,基本都是使用ofstream,ifstream,fstream
总结说明了matlab中对文件目录操作的一些函数及其用法,读写文件的函数及其用法
Android应用源码SdCard读写文件实例
用C语言实现的简单的文件读写,,适合C初学者,,,熟悉文件读写操作,
C++动态链接库读写文件
1.Linux下文件句柄方式,写二进制文件时一定要用O_BINARY 2.CFile,MFC封装的形式,不区分二进制或者文本文件方式读写 3.FILE,文件指针形式,写二进制文件时一定要用wb
多线程通信读写文件代码,根据其他的代码文档修改,用于学习多线程通信。
VC TCP实例,客户端连接,读写文件,编译通过
使用vbs读写文件(Adodb.Stream)方式,防止乱码
CStdioFile读写文件文档 VC6编写 代码完整, 打开直接可以编译使用