Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Want Help Reagarding Reading Text  RSS feed

 
khad M
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers
Hope all are fine.
Here is a one tricky Q.
Iam using the following code
to read the contents from a file.
*********************************************
FileOutputStream fos1 = new FileOutputStream(file);
for(long i=0;i<filelength;i++)
{
int b = fis1.read();
}
*******************************************
Question is,
After reading using read() method.......i want to print to console that particular character the Byte contains.How to do that..???

Regards
Khad M
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to read from an Output stream?
 
khad M
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
Why do you want to read from an Output stream?


B'cas i ant to compare that character contained by the Byte with my own defined character.???
Is it sounds good..!!!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But FileOutputStream does not have a read method.
The API states:
A file output stream is an output stream for writing data to a File or to a FileDescriptor.

Is your FileOutputStream actually connected to a file?
If it is you, you could use a FileInputStream to read it back in.
The code you have provided does not look correct.
You could read your byte into a single element byte
array, then construct a String object using whatever coding scheme you require, and print the resulting single character string.
[ November 08, 2002: Message edited by: Barry Gaunt ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!