Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. private File folder;
  2. private File file;
  3.  
  4. public SuperFile(File folder, File file) {
  5. this.folder = folder;
  6. this.file = file;
  7. }
  8.  
  9. public static void createFile(SuperFile superfile) throws IOException {
  10. if(superfile.getFolder().exists()) {
  11. System.out.println("Folder already exists.");
  12. } else {
  13. superfile.getFolder().mkdirs();
  14. System.out.println("Folder has been created.");
  15. }
  16.  
  17. if(superfile.getFile().exists()) {
  18. System.out.println("File already exists.");
  19. } else {
  20. superfile.getFile().createNewFile();
  21. System.out.println("File has been created.");
  22. }
  23. }
  24.  
  25. public static List<String> readLine(SuperFile superfile) throws IOException {
  26. double totalLines = 0;
  27. double currentLines = 0;
  28. LineNumberReader lnr = new LineNumberReader(new FileReader(superfile.getFile()));
  29. Scanner sc = new Scanner(superfile.getFile());
  30. List<String> s = new ArrayList<>();
  31. while(lnr.readLine() != null) totalLines++;
  32. lnr.close();
  33. while(sc.hasNextLine()) {
  34. currentLines++;
  35. s.add(sc.nextLine());
  36. System.out.println((currentLines / totalLines) * 100 + "%");
  37. }
  38. sc.close();
  39. System.out.println(totalLines);
  40. return s;
  41. }
  42.  
  43. public static List<String> readWord(SuperFile superfile) throws IOException {
  44. double totalWords = 0;
  45. double currentWords = 0;
  46. Scanner sc = new Scanner(superfile.getFile());
  47. List<String> s = new ArrayList<>();
  48. List<String> lines = Files.readAllLines(superfile.getFile().toPath());
  49. String totalstring = String.join("\n", lines.toArray(new String[lines.size()]));
  50. String[] words = totalstring.split("\\s+");
  51. totalWords = words.length;
  52. while(sc.hasNext()) {
  53. currentWords++;
  54. s.add(sc.next());
  55. System.out.println((currentWords / totalWords) * 100 + "%");
  56. }
  57. sc.close();
  58. System.out.println(totalWords);
  59. return s;
  60. }
  61.  
  62. public File getFolder() {
  63. return folder;
  64. }
  65.  
  66. public File getFile() {
  67. return file;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement