0

I have a static method that creates an xml file and I would like it to return the raw xml file as a string. After creating the xml file I would like to read from the file and convert it to a string. How do I go about doing so?

Bob
  • 821
  • 1
  • 17
  • 36

3 Answers3

2

http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/io/Files.html

Joiner.on('').join(Files.readLines(file, CharSet.fromName("UTF-8")))
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
1

you could turn to, for the file handling, to the apache.commons.io library.

This one has build in convenience functions for reading and storing files.

So for reading

org.apache.commons.io.FileUtils#readFileToString(File file) 

and for writing

org.apache.commons.io.FileUtils#writeStringToFile(File file, String data)

See here for javadoc http://commons.apache.org/io/

Joey
  • 1,349
  • 14
  • 26
0

Here is a variety of ways of doing it:

Community
  • 1
  • 1
dave.c
  • 10,910
  • 5
  • 39
  • 62