当前位置: 技术问答>java相关
请教文件操作。。。(在线)
来源: 互联网 发布时间:2015-10-21
本文导语: 我想读出txt 文档的内容,但是不行,请看看我这个程序。。。 谢谢 | FileInputStream fi = new FileInputStream(new File("d:/test.txt")); InputStreamReader isr = new InputStreamReader(fi,"GB2312"); StringBuffer bu...
我想读出txt 文档的内容,但是不行,请看看我这个程序。。。
谢谢
谢谢
|
FileInputStream fi = new FileInputStream(new File("d:/test.txt"));
InputStreamReader isr = new InputStreamReader(fi,"GB2312");
StringBuffer buffer = new StringBuffer();
int ch;
BufferedReader in = new BufferedReader(isr);
while ((ch = in.read()) > -1) {
buffer.append ((char)ch);
}
System.out.println(buffer.toString());
in.close();
InputStreamReader isr = new InputStreamReader(fi,"GB2312");
StringBuffer buffer = new StringBuffer();
int ch;
BufferedReader in = new BufferedReader(isr);
while ((ch = in.read()) > -1) {
buffer.append ((char)ch);
}
System.out.println(buffer.toString());
in.close();
|
well,let's go...
it's running in jdk1.4
//***************************************
RandomAccessFile raf=new RandomAccessFile("d:/smc.txt","rw");
String count=null;
while(raf.readLine()!=null)
{
count=raf.readLine();
System.out.println(count);
}
raf.close();
it's running in jdk1.4
//***************************************
RandomAccessFile raf=new RandomAccessFile("d:/smc.txt","rw");
String count=null;
while(raf.readLine()!=null)
{
count=raf.readLine();
System.out.println(count);
}
raf.close();