Guest User

Untitled

a guest
Dec 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class FileHandler {
  4. public String[] items;
  5. public File file;
  6. public FileHandler(String fileName){
  7. file = new File(fileName);
  8. }
  9. public void clearContents(){
  10. for (int i = 0; i <items.length;i++){
  11. items[i]=null;
  12. }
  13. }
  14. public void loadFileContents(){
  15. try{
  16. this.clearContents();
  17. BufferedReader bf = new BufferedReader(new FileReader(file));
  18. for(String s = null; (s = bf.readLine()) != null;)
  19. {
  20. items[items.length]=s;
  21. }
  22. bf.close();
  23. }catch(Exception exception)
  24. {}
  25. }
  26. public void saveFileContents(){
  27. try{
  28. PrintWriter pw = new PrintWriter(new FileWriter(file, false));
  29. for (String st:items){
  30. pw.println(st);
  31. pw.close();
  32. }
  33. }catch(Exception exception)
  34. {}
  35. }
  36. }
Add Comment
Please, Sign In to add comment