edit this page - page history - about editing

Writing a String to a File in Java


In particular, getting an InputStream from a String:

InputStream source = new ByteArrayInputStream(myString.getBytes("UTF-8")); 
IFile out = project.getFile(f + ".xml");
out.create(source, true, monitor);

This uses Eclipse's IFiles to set the file contents.

The major problem is that InputStreams know nothing of character encoding, thus the deprecation to use StringReader instead. (ref)

To achieve this without using Eclipse's framework, see this code.
Categories: Java | Todo | Tag-todo
edit this page - what links to here? - page history - top
Last edited by jevon jevon 119 months ago