• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to convert InputStreamReader to a File  RSS feed

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you convert a inputstreamReader to a file.
I had a file that has unicode special characters.
File theFile = new File(fileName);
I need to parse this file(xml) and pass ISO-8859-1.

To do this. I am converting it into
InputStream ins = new FileInputStream( theFile );
InputStreamReader isr = new InputStreamReader( ins, "UTF-8" );

I want to convert it back to a File object. How do I do 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
If you mean "given only the InputStreamReader, how can I recover the File object that it is reading from," you can't. There's no information about the file available from the InputStreamReader.

If you mean how can you put the information you're reading back into a file -- just create a FileWriter and use write() to put all the characters you read() into a new file. If you're trying to convert the original, then put all the data into a new file, close it, make sure everything's OK, then remove the old file and rename the new one.
[ July 27, 2004: Message edited by: Ernest Friedman-Hill ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!