• Post Reply Bookmark Topic Watch Topic
  • New Topic

question on FileInputStream

 
kedar parundekar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileInputStream fin=new FileInputStream("tata.doc");
int i;
while((i=fin.read())!=-1)
{
System.out.print((char)i);
}

If I run above code for abc.java instead of tata.doc -> then its working fine. Its printing containts of abc.java on the console.
But If I run for tata.doc -> then its printing something different on the console.
Why this happen?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not enough information provided for a full answer, but...

What output do you get? What output did you expect?

What is this .doc file? Is it a Microsoft Word document? If so, remember that's not a text file, it's binary (maybe compressed XML?). You can't just print it as raw characters.
 
Anupam Bhatt
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Peter said, and as far as i guess, you are trying to read a Microsoft Word document, which is not a text document.
 
shiquan yang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could create a new txt file,and try it again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!