-
-
Save timvisher/ea5c9b280c8407cd754d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1007 @ 01-19 11:19:24: ๐ฉ | |
tvisher@timvisher-rjmetrics.local:~ | |
๐ก cat > Desktop/TW_items.txt | |
stephen | |
charnock | |
^D | |
1008 @ 01-19 11:19:38: ๐ | |
tvisher@timvisher-rjmetrics.local:~ | |
๐ถ fg | |
emacs Application.java | |
[1]+ Stopped emacs Application.java | |
1008 @ 01-19 11:19:57: ๐ฉ | |
tvisher@timvisher-rjmetrics.local:~ | |
๐ก javac MyApplication.java | |
1009 @ 01-19 11:20:02: ๐ | |
tvisher@timvisher-rjmetrics.local:~ | |
๐ java MyApplication | |
stephen | |
charnock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class MyApplication { | |
//command line arguments | |
public static void main(String [] args) { | |
//the name of the file you want to open | |
String fileName = "/Users/tvisher/Desktop/TW_items.txt"; | |
//reference one line at a time | |
String line = null; | |
try { | |
//FileReader reads text files in the default encoding. | |
FileReader fileReader = new FileReader(fileName); | |
//Always wrap FileReader in BufferedReader. | |
BufferedReader bufferedReader = new BufferedReader(fileReader); | |
while((line = bufferedReader.readLine()) != null) { | |
System.out.println(line); | |
} | |
//Always close files. | |
bufferedReader.close(); | |
} | |
catch (FileNotFoundException ex) { | |
System.out.println("Unable to open file '" + fileName + "'" ); | |
} | |
catch(IOException ex) { | |
System.out.println("Error reading file '" + fileName + "'"); | |
//Or we could just do this: | |
//ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment