public static void main(String[] args) {
String pathString="D:/java/HelloWorld.txt";
readFile(pathString);
}
public static void readFile(String pathName){
String encoding="GBK";
File file=new File(pathName);
InputStreamReader reader=null;
if (file.isFile()&&file.exists()) {
try {
reader=new InputStreamReader(new FileInputStream(file),encoding);
BufferedReader bufferedReader=new BufferedReader(reader);
String string=null;
while ((string=bufferedReader.readLine())!=null) {
System.out.println(string);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if (reader!=null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}