FileInputStream fis = new FileInputStream(new File(“C:\\fileName.txt”));The above code doesn’t involve any looping over the file line by line, as it picks up whole content at once and assigns it to String.
int avail = fis.available();
byte[] bytes = new byte[avail];
fis.read(bytes, 0, avail);
String rfResponse = new String(bytes);
03 October 2008
reading File to String in Java
There are lots of ways to read the contents of File to String in Java. Here I present one of the simplest way to do the job.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment