• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...!!!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1771580
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for noticing the cross-post.
 
reply
    Bookmark Topic Watch Topic
  • New Topic