java如何用FileIputStream按行读取csv文件 求代码
展开全部
FileInputStream是按字节读取文件的
按行读取的话,用BufferedReader
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("ss.csv"));
String str = "";
while (null != (str = br.readLine())) {
System.out.println(str);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (br!= null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
用的相对路径,ss.csv和类放在一个文件夹里了
按行读取的话,用BufferedReader
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("ss.csv"));
String str = "";
while (null != (str = br.readLine())) {
System.out.println(str);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (br!= null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
用的相对路径,ss.csv和类放在一个文件夹里了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询