读取文件中的内容将其显示出来
2009-11-21 16:37
218 查看
//读取文件中的内容将其显示出来
public class ReadFile{
public static void main(String[] args) {
int b;
byte tom[] = new byte[1000];
File file = new File("c://system.xml");
try {
FileInputStream f = new FileInputStream(file);
b = f.read(tom,0,280);
while(b!=-1){
//StringBuffer str = new StringBuffer();
String str = new String(tom,0,b);
System.out.println(str);
break;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class ReadFile{
public static void main(String[] args) {
int b;
byte tom[] = new byte[1000];
File file = new File("c://system.xml");
try {
FileInputStream f = new FileInputStream(file);
b = f.read(tom,0,280);
while(b!=-1){
//StringBuffer str = new StringBuffer();
String str = new String(tom,0,b);
System.out.println(str);
break;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
相关文章推荐
- Hadoop实验:用java把hdfs系统里的文件内容读取出来,显示到屏幕
- C源程序:输入当前目录下的文本文件名称,尝试打开文件,逐个字符读取文件内容并显示出来
- web工程导出Excel文件打开时显示“Excel在 ** 中发现不可读取的内容。是否恢复此工作簿的内容?....”
- 实验 5.3.2 scandir 1. 用 scandir()读取目录内容。只显示以字母开头的文件
- 读取BMP文件并显示出来(C++实现)
- 怎么让文件的内容在textArea中显示出来?
- C# Visual Studio 2005中用FileStream将一个文件中的内容读取出来并赋给一个变量
- 使用Robot从txt文件中读取不同行的内容并显示(续)
- ASP读取显示TXT文件内容
- Asp.Net读取并显示Excel文件中的内容(OleDb方式)
- 从键盘输入若干个字符,逐个存到磁盘文件data.txt中,直到输入’\n’为止,并将建立的文本文件的内容在存入文件的同时,在屏幕上显示出来:
- 创建一个类实现读取一个文件中的每一行显示出来。
- 读取xml文件内容,并将其内容以treeview的方式展现出来
- 汇编语言:请写一个程序把当前目录下的TEXT.TXT文件中的字符读出来显示在屏幕上,当遇到结束符时就停止读取。
- 怎么让文件的内容在textArea中显示出来?
- js依次读取本地文件并显示内容
- VB.NET 打开Excel文件,读取Excel内容,添加到DataGridView中并显示
- 【ASP.NET 进阶】定时执行任务实现 (定时读取和修改txt文件数字内容,无刷新显示结果)
- 关于php读取文件内容 显示
- PHP 读取文本文件内容并分页显示