java中readLine()怎样用?
展开全部
public static String readFile2(String filePath) {
String fileContent = "";
//目标地址
File file = new File(filePath);
if (file.isFile() && file.exists()) {
try {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
try {
//循环,每次读一行
while ((line = reader.readLine()) != null) {
fileContent += line;
}
reader.close();
read.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return fileContent;
}
String fileContent = "";
//目标地址
File file = new File(filePath);
if (file.isFile() && file.exists()) {
try {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
try {
//循环,每次读一行
while ((line = reader.readLine()) != null) {
fileContent += line;
}
reader.close();
read.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return fileContent;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个问题不用问了,百度java中readLine()用法就ok
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询