NEW : REBASE THE ENTIRE WORKING PROJECT
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package Files;
|
||||
|
||||
import java.io.File; // Import the File class
|
||||
import java.io.FileNotFoundException; // Import this class to handle errors
|
||||
import java.util.Scanner; // Import the Scanner class to read text files
|
||||
|
||||
public class ReadFile {
|
||||
|
||||
public String data;
|
||||
|
||||
public String ReadFromFile(String path) {
|
||||
try {
|
||||
File myObj = new File(path);
|
||||
Scanner myReader = new Scanner(myObj);
|
||||
while (myReader.hasNextLine()) {
|
||||
data = myReader.nextLine();
|
||||
System.out.println(data);
|
||||
}
|
||||
myReader.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("An error occurred.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package Files;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class WriteFile {
|
||||
|
||||
BufferedWriter buffer = null;
|
||||
|
||||
public void WriteFile(String path, String input) throws Exception {
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter fileWriter = new FileWriter(path);
|
||||
buffer = new BufferedWriter(fileWriter);
|
||||
buffer.write(input);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (buffer != null) buffer.flush();
|
||||
// buffer.close();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error in closing the BufferedWriter" + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user