https://github.com/marknjunge/easyfiles
A simple way of performing common file interactions.
https://github.com/marknjunge/easyfiles
Last synced: 12 months ago
JSON representation
A simple way of performing common file interactions.
- Host: GitHub
- URL: https://github.com/marknjunge/easyfiles
- Owner: MarkNjunge
- License: other
- Created: 2016-12-26T16:11:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-12T11:55:24.000Z (over 8 years ago)
- Last Synced: 2025-04-09T13:19:50.638Z (over 1 year ago)
- Language: Java
- Size: 5.76 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EasyFiles
A Java & Kotlin library for simplifying common file interactions.
The library can:
1. Copy, move or delete a file.
2. Read and write a file by line.
3. Read and write the contents of a file in bytes.
4. Read the content of a file in tokens.
5. Get filename and extension.
# Usage
**Requires Java 7+**
**Java**
```Java
Path source = Paths.get("source.txt");
Path target = Paths.get("target.txt");
// Copy File
EasyFiles.copyFileTo(source, target, new EasyFiles.ActionListeners() { // Action Successful listener
@Override
public void actionSuccessful() {
System.out.println("Copy successful!");
}
});
// Delete file
EasyFiles.deleteFile(source, () -> System.out.println("Delete successful!"));
// Move file
EasyFiles.moveFile(source, target, null); // No listener
// Getting filename and extension
Map map = EasyFiles.getFileNameAndExtention(source);
map.get(EasyFiles.FILENAME);
map.get(EasyFiles.EXTENSION);
// Read and write files by line
List contentLines = EasyFiles.readFileAsLines(source);
EasyFiles.writeFileByLine(target, contentLines, true, null);
// Read and write files by bytes
byte[] contentBytes = EasyFiles.readFileAsBytes(source);
EasyFiles.writeFileByBytes(target, contentBytes, null);
// Read file using tokens
List tokens = EasyFiles.readFileTokens(source, "delimiter");
```
**Kotlin**
``` Kotlin
val source = Paths.get("source.txt")
val target = Paths.get("target.txt")
val extension = source.extension
val filename = source.filenameOnly
source.copyFileTo(target)
source.deleteFile()
source.moveFileTo(target)
source.readFileAsLines() // Returns: MutableList
source.writeFileByLine(content, append) // Append is optional
```
# Installation
Download the latest version from releases or clone the repository and add the files to your project.
# License
EasyFiles is licensed under Apache 2.0 License.