External references for file writer: https://www.programiz.com/java-programming/examples/append-text-existing-file Current Directory (of active program): https://www.programiz.com/java-programming/examples/current-working-directory File Writer: public void writeRecord(String pFilePath, String pRecordToWrite) throws IOException { System.out.println("Write Info: " + pRecordToWrite + " append string to file: - " + pFilePath); File file = new File(pFilePath); // appendmode FileWriter fr = new FileWriter(file, true); fr.write(pRecordToWrite + "\r\n"); fr.close(); } ===================================================== Buffered File Reader: public class FileBufferedReader { public static void main(String args[])throws Exception { //ArrayList arrayList = new ArrayList(); String path = "D:\\DeleteFilesToTest\\sheetMusicToFilter.txt"; try (BufferedReader br = new BufferedReader(new FileReader(path))) { String line; int i = 0; // It holds true till there is content in file while ((line = br.readLine()) != null) { //put into the ArrayList list: //arrayList.add(str); // Printing the file data i++; System.out.println(i + ". " +line); } } // Catch block to handle the exceptions catch (IOException e) { // Display pop up message if exceptionn occurs System.out.println( "Error while reading a file."); } //return arrayList; } } ================================== Read File records into ArrayList: public class ReadFileToTest { public ArrayList readBufferedFile(String pReadFilePath) { // Declaring a string and initializing it with // path of file present on the system ArrayList arrayList = new ArrayList(); String path = pReadFilePath; // Try block to check for exceptions try (BufferedReader br = new BufferedReader(new FileReader(path))) { // Declaring a new string String str; // It holds true till there is content in file while ((str = br.readLine()) != null) { //put into a list: arrayList.add(str); // Printing the file data System.out.println(str); } } // Catch block to handle the exceptions catch (IOException e) { // Display message if exceptionn occurs System.out.println( "Error while reading a file."); } return arrayList; } ================================== File Finder Dialog: public void getFilePath() { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showOpenDialog((Frame) null); if(option == JFileChooser.APPROVE_OPTION){ File file = fileChooser.getSelectedFile(); txtFileToTest.setText(file.getAbsolutePath()); }else{ txtFileToTest.setText("Save command canceled"); } } ================================== Directory Finder Dialog: public void getDirectory() { LocalDateTime myDateObj = LocalDateTime.now(); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println(formattedDate); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int option = fileChooser.showOpenDialog((Frame) null); if(option == JFileChooser.APPROVE_OPTION){ File file = fileChooser.getSelectedFile(); txtSaveResultsToDirectoryChoice.setText(file.getAbsolutePath() + "\\FilteredResults-" + formattedDate + ".txt"); }else{ txtSaveResultsToDirectoryChoice.setText("Open Folder command canceled"); } } =============================== ======================================== public class BufferedInputFile { // Throw exceptions to console: public static String read(String filename) throws IOException { // Reading input by lines: BufferedReader in = new BufferedReader( new FileReader(filename)); String s; StringBuilder sb = new StringBuilder(); while((s = in.readLine())!= null) sb.append(s + "\n"); in.close(); return sb.toString(); } public static void main(String[] args) throws IOException { System.out.print(read("BufferedInputFile.java")); } } /* (Execute to see output) *///:~ ============================================= public class FileOutputShortcut { static String file = "FileOutputShortcut.out"; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader( new StringReader( BufferedInputFile.read("FileOutputShortcut.java"))); // Here’s the shortcut: PrintWriter out = new PrintWriter(file); int lineCount = 1; String s; while((s = in.readLine()) != null ) out.println(lineCount++ + ": " + s); out.close(); // Show the stored file: System.out.println(BufferedInputFile.read(file)); } } /* (Execute to see output) *///:~ =============================================== ======================================== Using BufferedReader: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFileLineByLineUsingBufferedReader { public static void main(String[] args) { BufferedReader reader; try { reader = new BufferedReader(new FileReader("sample.txt")); String line = reader.readLine(); while (line != null) { System.out.println(line); // read next line line = reader.readLine(); } reader.close(); } catch (IOException e) { e.printStackTrace(); } } ============================================= Using Files: import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; public class ReadFileLineByLineUsingFiles { public static void main(String[] args) { try { List allLines = Files.readAllLines(Paths.get("sample.txt")); for (String line : allLines) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }