import java.io.*;
public class FileReader {
public String getFileAsString(File file){ FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
StringBuffer sb = new StringBuffer();
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while (dis.available() != 0) {
sb.append( dis.readLine() +"\n");
}
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
public static void main(String[] args) {
File file = new File("C:/setup.log");
FileReader fd = new FileReader();
String s = fd.getFileAsString(file);
System.out.print(s);
}
}
method getFileAsString get you the file as a single string. This program should be further improved by avoid using depricated APIs (DataInputStream)
Thanks,
Kannapiran