public static void read(String path) {
File file = new File(path);
if (!file.exists() || file.isDirectory()) {
System.out.println(path);
System.out.println("文件不存在或是path为文件夹");
return;
}
BufferedReader br = null;
try {
/**
* csv文件每个单元格使用,分割
* 默认ANSI编码
*/
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "gbk"));
String msg = "";
msg = br.readLine();
while (msg!=null) {
System.out.println(msg);
msg = br.readLine();
}
} catch (FileNotFoundException e) {
System.out.println("创建流文件异常:文件没找到");
e.printStackTrace();
} catch (IOException e) {
System.out.println("流文件读取异常:" + e.toString());
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
System.out.println("流文件关闭出现异常:" + e.toString());
e.printStackTrace();
}
}
}
}
Java 读取csv文件
最新推荐文章于 2024-01-11 10:24:15 发布