import java.io.*; public class FileIO { File file; int bufferSize = 16; public FileIO(File f){ file=f; } public FileIO(String s){ file=new File(s); } public FileIO(String s, int bs){ file=new File(s); bufferSize=bs; } public String content() { return read(); } public String read () { /* Open the file and * return the contents of it as a String. */ StringBuffer buffer = new StringBuffer(); try { FileInputStream is = new FileInputStream(file); BufferedReader in=new BufferedReader( new InputStreamReader(is)); String r=in.readLine(); while(r!=null){ buffer.append(r+"\n"); r=in.readLine(); } is.close(); } catch (Exception err) { /* Return an empty string on error */ buffer=new StringBuffer(); } return buffer.toString().trim(); } public String write (String s) { /* Open the file and write s to it */ String t=new String(); try{ byte[] b=s.getBytes(); FileOutputStream f = new FileOutputStream(file); f.write(b); f.close(); t="File saved."; } catch(Exception ex){ t="Error: "+ex.toString(); } return t; } public String append (String s) { String t=new String(); return t; } }