java根据文件所在的路径,从文本文件中读取内容
2009-04-23 20:54:52 来源:WEB开发网核心提示: /** * 根据文件所在的路径,从文本文件中读取内容<br> * * @param path * @return 从文本文件中读取内容 */ public String readFile(String path) { BufferedReader br; String read = "&
/**
* 根据文件所在的路径,从文本文件中读取内容<br>
*
* @param path
* @return 从文本文件中读取内容
*/
public String readFile(String path) {
BufferedReader br;
String read = "";
String readStr = "";
try {
File file = new File(path);
FileReader fileread = new FileReader(file);
br = new BufferedReader(fileread);
while ((read = br.readLine()) != null) {
readStr = readStr + read;
}
} catch (Exception ex) {
System.out.PRintln(ex.getMessage());
}
System.out.println("###readStr:" + readStr);
return readStr;
}
* 根据文件所在的路径,从文本文件中读取内容<br>
*
* @param path
* @return 从文本文件中读取内容
*/
public String readFile(String path) {
BufferedReader br;
String read = "";
String readStr = "";
try {
File file = new File(path);
FileReader fileread = new FileReader(file);
br = new BufferedReader(fileread);
while ((read = br.readLine()) != null) {
readStr = readStr + read;
}
} catch (Exception ex) {
System.out.PRintln(ex.getMessage());
}
System.out.println("###readStr:" + readStr);
return readStr;
}
更多精彩
赞助商链接