wood burning stoves 2.0*
The moose likes Java in General and the fly likes FileInputStream - Replace Characters - FileInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "FileInputStream - Replace Characters - FileInputStream" Watch "FileInputStream - Replace Characters - FileInputStream" New topic

FileInputStream - Replace Characters - FileInputStream

Brian Agius

Joined: Oct 30, 2002
Posts: 9
I have the following situation:

I am reading an XML file using FileInputStream and contents are sent to an unmarshaller method that accepts only FileInputStream. We have recently encountereda problem whereby the ampersnad character is not accpetable to the marshaller. My idea was to create a method that reads the file, replaces the ampersand character and writes back the contents to FileInputStream which is used by the unmarsahller.

The issue is that I have not found the way to write to FileInput Stream. The following is the code I am using for testing purposes:

static FileInputStream readInput()

StringBuffer buffer = new StringBuffer();
FileInputStream fis = new FileInputStream("E:\\XYZ.XML");
InputStreamReader isr = new InputStreamReader(fis,"UTF8");

Reader in = new BufferedReader(isr);

int ch;

while ((ch = in.read()) > -1)
String test = (Character.toString((char)ch));
if (test.equals("&"))
test = ".&";

return buffer.toString();

catch (IOException e)
return null;

Regards<br /> <br />BA
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41064
Indeed, it's not possible to write to an InputStream. This demonstrates the advantages of not using specific classes -like FileInputStream- in public interfaces. If the API was using the InputStream interface instead, it would be easy to filter the stream.

Ping & DNS - my free Android networking tools app
I agree. Here's the link: http://aspose.com/file-tools
subject: FileInputStream - Replace Characters - FileInputStream
Similar Threads
How can I get Unicode String of a String?
How a character save in 2 bytes in Java?
Accessing mp3 properties (128 bytes at the end) dirty hack...How to make this more efficient?
ASCII to EBCIDIC conversion error
file, UTF8