FileOperationsLibrary
is a Java library that simplifies basic and advanced file operations. It includes functionality for reading and writing files, appending to files, searching within files, and handling CSV file operations.
-
Basic File Operations
- Reading from a file
- Writing to a file
- Appending to a file
-
Advanced File Operations
- Searching for text within files
- Reading and writing CSV files with proper escaping of special characters
-
Download the JAR file:
- Locate the
FileOperationsLibrary.jar
in thedist
directory of this project.
- Locate the
-
Add the JAR file to your project:
- In NetBeans or your preferred IDE, right-click on your project.
- Select
Properties
. - Navigate to
Libraries
. - Click
Add JAR/Folder
and select theFileOperationsLibrary.jar
file.
import main.java.com.virul.fileops.FileReaderUtil;
import main.java.com.virul.fileops.FileWriterUtil;
import main.java.com.virul.fileops.FileSearchUtil;
import main.java.com.virul.fileops.FileFormatUtil;
String content = FileReaderUtil.readFile("path/to/your/file.txt");
System.out.println(content);
FileWriterUtil.writeFile("path/to/your/file.txt", "Hello, World!");
FileWriterUtil.appendToFile("path/to/your/file.txt", "\nAppending this line.");
List<String> results = FileSearchUtil.searchInFile("path/to/your/file.txt", "search keyword");
for (String line : results) {
System.out.println(line);
}
List<String[]> csvData = FileFormatUtil.readCSV("path/to/your/file.csv");
for (String[] row : csvData) {
System.out.println(String.join(", ", row));
}
List<String[]> data = new ArrayList<>();
data.add(new String[]{"Name", "Age", "City"});
data.add(new String[]{"Alice", "30", "New York"});
FileFormatUtil.writeCSV("path/to/your/file.csv", data);
List<String[]> data = new ArrayList<>();
data.add(new String[]{"id", "Name", "Address", "DOB", "Mobile"});
data.add(new String[]{"1", "John Doe", "123 Main St, Apt 4B", "1990-01-01", "555-1234"});
FileFormatUtil.writeCSV("path/to/your/file.csv", data);
- Clone the repository:
git clone https://github.com/iamvirul/FileOperationsLibrary.git
- Build the project:
- Open the project in NetBeans.
- Go to
Run > Clean and Build Project
.
- Locate the JAR file:
- The JAR file will be located in the
dist
directory.
- The JAR file will be located in the
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
This project is licensed under the MIT License - see the LICENSE file for details.
Virul Nirmala Wickramasinghe