File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem reading a file

 
R Dom
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your program looks ok for me. your input file has any blank line?
 
R Dom
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no it doesnt have any blank line.
 
Carey Brown
Ranch Hand
Pie
Posts: 1066
9
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try replacing line 10 with
System.out.println( "'" + line + "'" ); // double-quote quote double-quote
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you think that will make any difference? What about a test using the String methods before printing?
 
anirudh jagithyala
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi R Dom,

Could you post the entire code.....?
Might be you are printing some blank space.........

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I missed the single quotes. Sorry. That is what comes from using 3mm tall writing on my screen.
 
R Dom
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 24 try defining line like this

 
R Dom
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ken jun wrote:In line 24 try defining line like this



I tried that before it didnt work!
 
ken jun
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic