Skip to content

Instantly share code, notes, and snippets.

@timvisher
Created January 19, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timvisher/ea5c9b280c8407cd754d to your computer and use it in GitHub Desktop.
Save timvisher/ea5c9b280c8407cd754d to your computer and use it in GitHub Desktop.
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
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