[java]代码库
try {
String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
File file = new File("d:/aa.txt"); //文件位置
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null) {
str+=lineTXT.toString();
}
read.close();
}else{
System.out.println("找不到指定的文件!");
}
} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}