java 文件读写_FileReader
2009-12-30 21:14:37 来源:WEB开发网核心提示:package test;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class Test { public static void main(Stri
package test;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
public static void main(String arg[]) {
String fileName = "E:\\share\\test.txt";
String writeData = "HelloWorld!\r\nnihao我的内存是3G的 ";
File file = new File(fileName);
if(file.exists()){
file.delete();
}
char[] byteOutData = writeData.toCharArray();
char[] byteInData = new char[50];
int length = 0;
try {
file.createNewFile();
if(file.exists() && file.canWrite()){
FileWriter fileWrite = new FileWriter(file);
fileWrite.write(byteOutData);
fileWrite.close();
}
if (file.exists() && file.canRead()) {
FileReader fileReader = new FileReader(file);
while((length = fileReader.read(byteInData)) !=-1){
System.out.PRint(new String(byteInData,0,length));
}
fileReader.close();
}
} catch (IOException e) {
System.out.println("IOException occur");
e.getMessage();
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whb3118/archive/2009/12/29/5099733.aspx
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
public static void main(String arg[]) {
String fileName = "E:\\share\\test.txt";
String writeData = "HelloWorld!\r\nnihao我的内存是3G的 ";
File file = new File(fileName);
if(file.exists()){
file.delete();
}
char[] byteOutData = writeData.toCharArray();
char[] byteInData = new char[50];
int length = 0;
try {
file.createNewFile();
if(file.exists() && file.canWrite()){
FileWriter fileWrite = new FileWriter(file);
fileWrite.write(byteOutData);
fileWrite.close();
}
if (file.exists() && file.canRead()) {
FileReader fileReader = new FileReader(file);
while((length = fileReader.read(byteInData)) !=-1){
System.out.PRint(new String(byteInData,0,length));
}
fileReader.close();
}
} catch (IOException e) {
System.out.println("IOException occur");
e.getMessage();
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whb3118/archive/2009/12/29/5099733.aspx
[]
- ››JavaScript拖拽原理的实现
- ››javascript事件列表解说
- ››Javascript代码优化工具UglifyJS
- ››Java Bean属性值动态设置
- ››JavaScript Confirm 失效的解决办法
- ››JavaScript页面内拖拽原理分析
- ››javascript中select的常用操作
- ››javascript+css无刷新实现页面样式的更换
- ››Java Web Services:不使用客户端证书的WS-Securit...
- ››Java开发2.0: 使用Amazon SimpleDB实现云存储,第...
- ››Java异常处理及其应用
- ››Java中遍历大容量map的正确方法
更多精彩
赞助商链接