• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in reading this particular text file, what is the problem with it..  RSS feed

 
Hindusthan Kamal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai to all..,

I had developed an application to read the text file that is stored in my computer from mobile, all are working fine but some files create problems in reading the file content, like the file i had attached with this..

Can any one please tell why this particular file creates problem in reading the contents...

I had attached a text file with this...


and the code I am using is



I try'd with BufferedReader also, but have the same problem,

Can any one please give me a solution for this..
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I imagine "getchar" is a String that's initialized to "" -- you haven't shown its declaration.

read() doesn't return "0" except when you read the character whose value is 0; read() returns -1 to indicate end of file, so your loop should test for -1. If your file doesn't contain a 0 -- and text files generally won't! -- then this will loop forever. Change that 0 to a -1 and this will work.

That said, this is horrifying code -- it's about the least efficient way to read a file into a String that I could imagine. Something like this is infinitely better:

 
Hindusthan Kamal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you reply Ernest Friedman-Hill

It's an wounder full suggestion...

I try'd with your code it's working fine but with this code also it's generates some error in reading some files.(I had attached a text file please try your code with this file).

Content in this file is not important but the first two lines are important, if we can read the first two lines its enough to get the name from the contact number and the date sent.

Try it and please guide me through this...

Have a great day...!!!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1771580
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for noticing the cross-post.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!