| Author |
Problem reading a file
|
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
I am reading text file in java using following code
When i execute the code i am getting output as blank text in first line and then all the file details.
file details are :
6
123
3456
output:
blank line
6
123
3456
Anyone can help me with this? I am doing anything wrong in code?
|
Cheers,
RD
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
your program looks ok for me. your input file has any blank line?
|
 |
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
|
no it doesnt have any blank line.
|
 |
Carey Brown
Ranch Hand
Joined: Nov 19, 2001
Posts: 159
|
|
Try replacing line 10 with
System.out.println( "'" + line + "'" ); // double-quote quote double-quote
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
Do you think that will make any difference? What about a test using the String methods before printing?
|
 |
anirudh jagithyala
Ranch Hand
Joined: Dec 07, 2010
Posts: 41
|
|
hi R Dom,
Could you post the entire code.....?
Might be you are printing some blank space.........
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Campbell Ritchie wrote:Do you think that will make any difference?
If the blank line does not now equal two single quotes then the blank line comes from somewhere else.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
I missed the single quotes. Sorry. That is what comes from using 3mm tall writing on my screen.
|
 |
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
Here is my full code
Here is my output from code above:
''
'6'
'2, 3, 5'
'1, 3, 5'
'4'
'1, 3'
'4, 6'
'1, 5'
'p'
'q'
''
'p, q'
'p'
Input file is as follows:
6
2, 3, 5
1, 3, 5
4
1, 3
4, 6
1, 5
p
q
p, q
p
|
 |
anirudh jagithyala
Ranch Hand
Joined: Dec 07, 2010
Posts: 41
|
|
Hey Dom,
Your code works fine for me..
i get the output as that of the file.
your output is obtained only when there is a space in the file. You could check comparing the output with space.
Please try out with some other files to read...... and i feel its the error is with the file you read.
|
 |
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
|
I dont know why it doesnt work for me.. I dont have any spaces in input file.. I cant attach my txt file..anybody knows how can i attache my input file? this forum doesnt allow me to attach txt files.
|
 |
ken jun
Ranch Hand
Joined: Apr 23, 2010
Posts: 46
|
|
In line 24 try defining line like this
|
 |
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
ken jun wrote:In line 24 try defining line like this
I tried that before it didnt work!
|
 |
ken jun
Ranch Hand
Joined: Apr 23, 2010
Posts: 46
|
|
|
your code work properly in my netbean.... Could you tell me what IDE are you using and what's your OS? Have you try run your code in a virtual machine in your PC?
|
 |
R Dom
Greenhorn
Joined: Sep 08, 2010
Posts: 19
|
|
ken jun wrote:your code work properly in my netbean.... Could you tell me what IDE are you using and what's your OS? Have you try run your code in a virtual machine in your PC?
I am using Eclipse Helios on Windows 7...
Does it matter? Java is suppose to be platform independent.
|
 |
ken jun
Ranch Hand
Joined: Apr 23, 2010
Posts: 46
|
|
R Dom wrote:
ken jun wrote:your code work properly in my netbean.... Could you tell me what IDE are you using and what's your OS? Have you try run your code in a virtual machine in your PC?
I am using Eclipse Helios on Windows 7...
Does it matter? Java is suppose to be platform independent.
I know java is suppose to be platform independent. i just want to know your IDE and OS, it doesn't matter
|
 |
 |
|
|
subject: Problem reading a file
|
|
|