reader problem...

/*

* Main.java

*

* Created on August 7, 2006, 10:42 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package readtext;

import java.io.*;// For input & output classes

import java.util.Date;// For the Date class

publicclass create_table{

public create_table(){

}

publicstaticvoid main(String[] args)

throws IOException{

//Read from file

BufferedReader in =new BufferedReader(

new FileReader("C:/Documents and Settings/seng/Desktop/testfile/VehicleNode.txt"));

BufferedReader in1 =new BufferedReader(

new FileReader("C:/Documents and Settings/seng/Desktop/testfile/VehicleNode.txt"));

// Output directory name

String dirName ="C:/Documents and Settings/seng/Desktop/testfile";

File aFile =new File(dirName,"VehiclePosition.txt");

aFile.createNewFile();// Now create a new file if necessary

if(!aFile.isFile())// Verify we have a file

{

System.out.println("Creating " + aFile.getPath() +" failed.");

return;

}

//Variable declarations

String text;

String atext;

while ((text = in.readLine()) !=null)// problem here

{

while ((atext = in.readLine()) !=null)

{

}

System.out.println(text);

}

}

}

i wander why thewhile ((text = in.readLine()) !=null)

can not fully read for the .txt file? it only read for 1st sentance...

howeverwhile ((text = in.readLine()) !=null)

is succesfull to read all text.

[3255 byte] By [wilfrid100a] at [2007-10-3 2:50:00]
# 1
> while ((text = in.readLine()) != null) > while ((text = in.readLine()) != null) these are the same statements?
Tom_Timpsona at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 2

while ((text = in.readLine()) != null) // problem here

{

while ((atext = in.readLine()) != null)

{

}

System.out.println(text);

}

It only reads one line because: it reads first line, then the inner loop goes through the rest of the file doing nothing else, and then the outer loop is stuck at the end of the file and has nothing left to read itself. Get rid of the inner loop.

CeciNEstPasUnProgrammeura at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 3

soli about my mistake...

is

while((text = in.readLine()) != null)

and

while ((atext = in.readLine() != null)

if really i can not separate the readLine()

by using 2 in.readLine()

(outer & inner)?

wilfrid100a at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 4
Read what Ceci wrote in reply #2.kind regards,Jos
JosAHa at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 5
He has an "in" and an "in1". Maybe the inner loop should use "in1". And, if so, the in1 BufferedReader should be re-initialized within the outer loop (but not inside the inner loop).I don't know if having two readers at the same time on the same file works, though.
doremifasollatidoa at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 6

> He has an "in" and an "in1". Maybe the inner loop

> should use "in1". And, if so, the in1 BufferedReader

> should be re-initialized within the outer loop (but

> not inside the inner loop).

>

> I don't know if having two readers at the same time

> on the same file works, though.

Probably. But whatever it's supposed to do, I probably wouldn't do it that way.

CeciNEstPasUnProgrammeura at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 7
may i know is tat got any way to solve this problem?
wilfrid100a at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 8
> may i know is tat got any way to solve this problem?Can you not get what you need with one reader? If not, what are you trying to do?
zadoka at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...
# 9

actaully i have 2 set of data which abit like below:

coordinate table

-

| segment_ID | staring_Pnt X | starting _pnt Y | end_pnt X | end_pnt Y |

--

sensor table

-

| sensor_ID | segment_ID |time|

-

base on here i would like to make a relationship between 2 segment_ID

, so that when i search for the sensor_ID

my output will let me know which coordination it is....

my concept

now i am trying to read 1 line from coordination table and after that compare with whole table of the sensor table.

question

1) Doesn't this mean i have to use 2 readLine( )?

2) i still haven't test to read 2 different file, is that the same result will be happen as reading the 2 same file like before?

wilfrid100a at 2007-7-14 20:38:49 > top of Java-index,Java Essentials,New To Java...