读取文件
来源:互联网 发布:怎么发送淘宝店铺链接 编辑:程序博客网 时间:2024/06/05 11:56
package com.company.internationalticket.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class ReadFileUtil {
public String readFile(String path){
if(path == null || "".equals(path)){
return "路径不合法,传入的路径为:" + path;
}
File file = new File(path);
String result = "";
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));// 构造一个BufferedReader类来读取文件
String s = null;
while ((s = br.readLine()) != null) {
// 使用readLine方法,一次读一行
result = result + "\n" + s;
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class ReadFileUtil {
public String readFile(String path){
if(path == null || "".equals(path)){
return "路径不合法,传入的路径为:" + path;
}
File file = new File(path);
String result = "";
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));// 构造一个BufferedReader类来读取文件
String s = null;
while ((s = br.readLine()) != null) {
// 使用readLine方法,一次读一行
result = result + "\n" + s;
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
0 0
- 文件读取(读取图片)
- 读取文件
- 读取文件
- 文件读取
- 文件读取
- 文件读取
- 读取文件
- 读取文件
- 读取文件
- 读取文件
- 文件读取
- 读取文件
- 文件读取
- 文件读取
- 读取文件
- 读取文件
- 文件读取
- 读取文件
- [LeetCode][Java] Sum Root to Leaf Numbers
- Linux下TCP keepalive属性的表现
- mysql Plugin 'InnoDB' init function returned error
- vector之reserve函数
- python 逻辑表达式应用
- 读取文件
- Ionic入门
- SQL查询语句(一)
- How do I sort an array of hashes by a value in the hash?
- JXLS-----JXLS读取Excel实例
- 第一周周三
- hdoj 1213 How Many Tables 【并查集】
- 机房收费系统——再回首
- 查找文件中的某个内容出现的次数