Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private File folder;
- private File file;
- public SuperFile(File folder, File file) {
- this.folder = folder;
- this.file = file;
- }
- public static void createFile(SuperFile superfile) throws IOException {
- if(superfile.getFolder().exists()) {
- System.out.println("Folder already exists.");
- } else {
- superfile.getFolder().mkdirs();
- System.out.println("Folder has been created.");
- }
- if(superfile.getFile().exists()) {
- System.out.println("File already exists.");
- } else {
- superfile.getFile().createNewFile();
- System.out.println("File has been created.");
- }
- }
- public static List<String> readLine(SuperFile superfile) throws IOException {
- double totalLines = 0;
- double currentLines = 0;
- LineNumberReader lnr = new LineNumberReader(new FileReader(superfile.getFile()));
- Scanner sc = new Scanner(superfile.getFile());
- List<String> s = new ArrayList<>();
- while(lnr.readLine() != null) totalLines++;
- lnr.close();
- while(sc.hasNextLine()) {
- currentLines++;
- s.add(sc.nextLine());
- System.out.println((currentLines / totalLines) * 100 + "%");
- }
- sc.close();
- System.out.println(totalLines);
- return s;
- }
- public static List<String> readWord(SuperFile superfile) throws IOException {
- double totalWords = 0;
- double currentWords = 0;
- Scanner sc = new Scanner(superfile.getFile());
- List<String> s = new ArrayList<>();
- List<String> lines = Files.readAllLines(superfile.getFile().toPath());
- String totalstring = String.join("\n", lines.toArray(new String[lines.size()]));
- String[] words = totalstring.split("\\s+");
- totalWords = words.length;
- while(sc.hasNext()) {
- currentWords++;
- s.add(sc.next());
- System.out.println((currentWords / totalWords) * 100 + "%");
- }
- sc.close();
- System.out.println(totalWords);
- return s;
- }
- public File getFolder() {
- return folder;
- }
- public File getFile() {
- return file;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement