A simple Java class for file management operations including creating, writing, reading, and deleting files.
-
Creating a File:
- Use the
createFile(String fileName)
method to create a new file with the specified file name.
createFile("example.txt");
- Use the
- Use the writeToFile(String fileName, String content) method to write content to a file.
writeToFile("example.txt", "Hello, this is a sample text! 😀");
- Reading Content from a File:
Use the readFromFile(String fileName) method to read content from a file.
String content = readFromFile("example.txt");
System.out.println("File content: " + content);
- Deleting a File:
Use the deleteFile(String fileName) method to delete a file.
deleteFile("example.txt");
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
// Create a file
FileManager.createFile("example.txt");
// Write content to the file
FileManager.writeToFile("example.txt", "Hello, this is a sample text! 😀");
// Read content from the file
String content = FileManager.readFromFile("example.txt");
System.out.println("File content: " + content);
// Delete the file
FileManager.deleteFile("example.txt");
} catch (IOException e) {
System.err.println("An error occurred: " + e.getMessage());
}
}
}
This project is licensed under the MIT License - see the LICENSE file for details.