Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class FileHandler {
- public String[] items;
- public File file;
- public FileHandler(String fileName){
- file = new File(fileName);
- }
- public void clearContents(){
- for (int i = 0; i <items.length;i++){
- items[i]=null;
- }
- }
- public void loadFileContents(){
- try{
- this.clearContents();
- BufferedReader bf = new BufferedReader(new FileReader(file));
- for(String s = null; (s = bf.readLine()) != null;)
- {
- items[items.length]=s;
- }
- bf.close();
- }catch(Exception exception)
- {}
- }
- public void saveFileContents(){
- try{
- PrintWriter pw = new PrintWriter(new FileWriter(file, false));
- for (String st:items){
- pw.println(st);
- pw.close();
- }
- }catch(Exception exception)
- {}
- }
- }
Add Comment
Please, Sign In to add comment