|
||
|
|||
|
I have a file that contains
1 2 3 4 5 6 7 8 9 I have a scanner that reads it, puts it into a String, and then attempts to use the split method to tokenize it. The problem is that it isn't counting \n as a delimiter. Java Code
try {
Scanner scan = new Scanner(theFile);
while(scan.hasNextLine()) {
n++;
stringForm += scan.nextLine();
} //end while
//make array
square = new int[n][n];
//put ints into array
String[] tokens = stringForm.split("\\s");
for(int i=0;i<tokens.length;i++) { //loop through array
for(int rowN=0;rowN<n;rowN++) {
for(int colN=0;colN<n;colN++) {
System.out.println(tokens[i]);
square[rowN][colN] = Integer.parseInt(tokens[i]); //initialize array
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Question | lotus | Loops & Control Statements | 3 | 20-06-2009 08:30 AM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jbutton java jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? |