Created
May 7, 2014 01:12
-
-
Save CSEmbree/661033e5b4287f73c9fc 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
hello;there;senor | |
how | |
are | |
you;today |
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
/* | |
* Example opening and reading a text file in Java using: | |
* File, Scanner, StringTokenizer | |
* | |
*/ | |
import java.io.*; | |
import java.util.Scanner; | |
import java.util.StringTokenizer; | |
class test { | |
public static void main(String[] args) { | |
String fName = "data.txt"; | |
try{ | |
File f = new File(fName); | |
Scanner s = new Scanner( f ); | |
String delim = ";"; // space delimiterized | |
String sentence = ""; //each sentence | |
String word = ""; //each word of a sentence | |
while( s.hasNext() == true) { | |
sentence = s.next(); | |
StringTokenizer tok = new StringTokenizer(sentence, delim); | |
while (tok.hasMoreTokens() == true) { | |
word = tok.nextToken(); | |
System.out.println("word: " + word); | |
} | |
} | |
} catch (FileNotFoundException fnfe) { | |
System.out.println("ERROR: File '" + fName + "'!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment