Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public static String readTextFile(String path)
  2. {
  3. String content = null;
  4. try
  5. {
  6. File file = new File(path);
  7. Scanner scanner = new Scanner(file);
  8. content = "";
  9. while (scanner.hasNextLine())
  10. {
  11. String line = scanner.nextLine();
  12. content += line + "\r\n";
  13. }
  14.  
  15. }
  16. catch (Exception ex)
  17. {
  18.  
  19. }
  20.  
  21. return content;
  22.  
  23. }
  24.  
  25. public static boolean writeTextFile(String path, String content)
  26. {
  27. boolean success = false;
  28. try
  29. {
  30. File file = new File(path);
  31. PrintWriter writer = new PrintWriter(path);
  32. writer.print(content);
  33. writer.close();
  34. success = true;
  35. }
  36.  
  37. catch (Exception ex) {}
  38. return success;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement