How to read file line by line?
2008-07-16 16:58
302 查看
since readLine() of DataInputStream is depreacted, now we can use BufferReader to do this job.
public static void main(String args[]){
try {
File file = new File("d://myfile.txt");
FileInputStream fis = new FileInputStream(file );
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
while (( line = br.readLine()) != null){
System.out.println(line);
}
fis.close();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]){
try {
File file = new File("d://myfile.txt");
FileInputStream fis = new FileInputStream(file );
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
while (( line = br.readLine()) != null){
System.out.println(line);
}
fis.close();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
相关文章推荐
- How to read a file line by line?
- Expect script to read file line by line
- how to read file by ZipFile
- Shell Script Utility To Read a File Line By Line
- How to upload file to SharePoint via commandline?
- How to read a PCap file from Wireshark with C++
- How to Take Ownership of a File/Folder Using Command-Line in Windows 7 or newer version System
- Tcl/TK -- How to read a ini file
- How to Read and Understand a Scientific Paper: A Step-by-Step Guide for Non-Scientists
- My Wiki: How to read a properties file in a web application
- How to read Mac .DMG file in Linux or PC(II)
- Bash Shell read file line by line and substring
- How to commit SVN(subversion) file in Notepad++ by NppExec plugin
- bash read file line by line
- How to read Json file or text file in Spark
- how to read a single line integer until '\n' is found
- How To Open Physical Standby For Read Write Testing and Flashback
- How to mount partition with ntfs file system and read write access
- How to open/read/write a local file from an applet
- [Delphi XE6 FireMonkey ] How to manipulate pixels on a bitmap by scanline property.