You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. import java.io.*;
  2. import java.util.Scanner;
  3. public class Storage implements StorageInterface {
  4. @Override
  5. public void export() {
  6. }
  7. @Override
  8. public void load() {
  9. }
  10. public boolean writeFile(String path, String content) {
  11. if (!path.isEmpty() && !content.isEmpty()) {
  12. try {
  13. BufferedWriter writer = new BufferedWriter(new FileWriter(path, false));
  14. writer.append(content);
  15. writer.close();
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. return false;
  19. }
  20. return true;
  21. }
  22. return false;
  23. }
  24. public String readFile(String path) {
  25. if (!path.isEmpty()) {
  26. StringBuilder data = new StringBuilder();
  27. try {
  28. File f = new File(path);
  29. Scanner myReader = new Scanner(f);
  30. while (myReader.hasNextLine()) {
  31. data.append(myReader.nextLine());
  32. }
  33. myReader.close();
  34. } catch (FileNotFoundException e) {
  35. e.printStackTrace();
  36. return null;
  37. }
  38. return data.toString();
  39. }
  40. return null;
  41. }
  42. }