读取一个文件中的内容到String中
2012-11-07 22:06
267 查看
/**
* readFileContent把json文件中的内容读取到一个String中返回
* @param name
* @param @return 设定文件
* @return String DOM对象
* @Exception 异常对象
* @创建人: MaJian
* @创建时间:2012-11-7 下午12:57:00
* @修改人: MaJian
* @修改时间:2012-11-7 下午12:57:00
* @修改备注:
*/
private String readFileContent(String fileName) throws IOException {
File file = new File(fileName);
BufferedReader bf = new BufferedReader(new FileReader(file));
String content = "";
StringBuilder sb = new StringBuilder();
while(content != null){
content = bf.readLine();
if(content == null){
break;
}
sb.append(content.trim());
}
bf.close();
return sb.toString();
}
* readFileContent把json文件中的内容读取到一个String中返回
* @param name
* @param @return 设定文件
* @return String DOM对象
* @Exception 异常对象
* @创建人: MaJian
* @创建时间:2012-11-7 下午12:57:00
* @修改人: MaJian
* @修改时间:2012-11-7 下午12:57:00
* @修改备注:
*/
private String readFileContent(String fileName) throws IOException {
File file = new File(fileName);
BufferedReader bf = new BufferedReader(new FileReader(file));
String content = "";
StringBuilder sb = new StringBuilder();
while(content != null){
content = bf.readLine();
if(content == null){
break;
}
sb.append(content.trim());
}
bf.close();
return sb.toString();
}
相关文章推荐
- 如何用java读取一个txt 文件内的内容并把它赋值与String里?
- Sprint读取配置文件内容格式的String
- objective-c 读取文本文件内容(stringWithContentsOfFile和initWithContentsOfFile)
- 编写一个程序,从标准输入一行一行地读取文本,并完成如下任务:如果文件中有两行或更多行相邻的文本内容相同,那么就打印其中一行,其余行不打印。
- C++读取文件所有内容+写一个新文件
- 编写一个业务函数,实现按行读取文件。把内容按照第三种内存模型打包数据传出,把行数通过函数参数传出。
- [Java] Java序列化将一个对象的内容保存到文件和从文件读取对象
- php读取一个文件后就清除文件的内容
- 读取一个SQL文件 + 批量执行batchUpdate(String[ ])
- Python 读取文件替换其中的内容并输出到一个新的文件内
- 按字符串读取文件内容NSString stringWithContentsOfFile: (NSString类方法)
- 第二周第四天(解析/过滤文件/找d盘里的所有txt文件/FileInputStream/FileOutputStream/拷贝文件/readLine读取一个文本行/在一个文档里写入内容)
- shell读取一个文件内容到变量并逐一赋值
- 今天在ASP.NET上在写一个读取EXCEL文件内容的功能,但是IE8貌似把文件路径给屏蔽了,在IE6下面读取正常!有啥好办法?
- 如何读取一个本地Json文件并查询该文件展示其内容
- Demo:把文件内容读入一个String
- . <WP7>读取工程中的一个文件内容
- C语言逐行读取文件内容,写入另外一个文件
- 8.9 编写函数打开文件用于输入,将文件内容读入 string 类型的 vector 容器,每一行存储为该容器对象 的一个元素。8.10 重写上面的程序,把文件中的每个单词存储为 容器的一个元素