从txt中读出文本内容(博文专用)
2014-02-24 18:39
183 查看
方法1:定义txt内容同等大小的数组,一次性读出文本的所有内容。
File file = new File("D:\\xx.txt");
Long fileLengthLong = file.length();
byte[] fileContent = new byte[fileLengthLong.intValue()];
try {
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(fileContent);
inputStream.close();
} catch (Exception e) {
// TODO: handle exception
}
String string = new String(fileContent);
方法2:按行循环读取文本内容.
BufferedReader in = new BufferedReader(new FileReader("D:\\xx.txt"));
String line = null;
while((line = in.readLine())!=null)
{
System.out.println(line);
}
File file = new File("D:\\xx.txt");
Long fileLengthLong = file.length();
byte[] fileContent = new byte[fileLengthLong.intValue()];
try {
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(fileContent);
inputStream.close();
} catch (Exception e) {
// TODO: handle exception
}
String string = new String(fileContent);
方法2:按行循环读取文本内容.
BufferedReader in = new BufferedReader(new FileReader("D:\\xx.txt"));
String line = null;
while((line = in.readLine())!=null)
{
System.out.println(line);
}
相关文章推荐
- 关于txt文本的内容与html页面上显示的内容格式一致的问题
- android 按行读取txt文本内容
- ajax读取txt文本内容
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- NGUI (三)加载txt文本内容
- txt文本内容写入数据库&MySQL基本语法
- 1.读取TXT文本内容
- 第一篇博文:TXT文本中找出所有网址
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- [object-c]读取txt文本内容
- 把文本文件中内容以行的方式读出,可以跳过空格等字符
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- C#控制台基础 file.readalllines一行一行的读取一个txt文本,把txt中的内容放到一个string数组里
- 2.读取TXT文本内容,显示至图形界面中
- R语言︱文件读入、读出一些方法罗列(批量xlsx文件、数据库、文本txt、文件夹)
- PHP将富文本内容去除各类样式图片等只保留txt文本内容(作用于SEO的description)
- Flex 取得文本(txt)内容,并且输出是汉字
- QT中如何实现将textEdit中的内容完全存入txt文本中包括换行
- 查看两个TXT文本中内容的区别