https://github.com/abarhub/filerw
File read write
https://github.com/abarhub/filerw
file fixed-width fixedlength java
Last synced: about 1 month ago
JSON representation
File read write
- Host: GitHub
- URL: https://github.com/abarhub/filerw
- Owner: abarhub
- Created: 2012-07-19T08:28:34.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2021-06-06T09:45:49.000Z (almost 5 years ago)
- Last Synced: 2023-06-30T10:47:08.439Z (almost 3 years ago)
- Topics: file, fixed-width, fixedlength, java
- Language: Java
- Homepage:
- Size: 404 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE-2.0.txt
Awesome Lists containing this project
README
Filerw
======
[](https://github.com/abarhub/filerw/releases/latest)
[](https://travis-ci.com/abarhub/filerw)
[](https://codecov.io/gh/abarhub/filerw)

[](https://maven-badges.herokuapp.com/maven-central/com.github.abarhub.filerw/filerw)
[](https://javadoc.io/doc/com.github.abarhub.filerw/filerw)
File read write with enum class
Dépendance Maven
----------------
```xml
com.github.abarhub.filerw
filerw
1.0.0
```
Javadoc
-------
[Javadoc version 1.0.0](https://abarhub.github.io/filerw/documentation/version_1.0.0/apidocs)
[Javadoc version 0.2.0](https://abarhub.github.io/filerw/documentation/version_0.2.0/apidocs)
[Javadoc version 0.1.0](https://abarhub.github.io/filerw/documentation/version_0.1.0/apidocs)
[Javadoc version 0.27](https://abarhub.github.io/filerw/documentation/version_0.27/apidocs)
Explication
-----------
[Documentation](https://abarhub.github.io/filerw/)
version 0.1.0 : compatible avec java 8
Pour l'utiliser avec une version inferieur à java 5, il faut utiliser une version inférieure à la version 0.1.0.
Exemple d'utilisation
---------------------
Pour un fichier avec le format suivant :
| Nom du champs | position sur une ligne | taille de la ligne |
| ------------- |--------------:| -----:|
| nom | 0 | 30 |
| prenom | 30 | 30 |
| date de naissance | 60 | 8 |
Le séparateur est le retour à la ligne.
Exemple de fichier:
```
Newton Isaac 04011643
Einstein Albert 14103879
Copernic Nicolas 19021473
```
Voici la classe pour définir le format du fichier :
```java
public enum FormatPersonnes implements Field {
Nom(0, 30), Prenom(30, 30), DateNaissance(60, 8);
private FieldsListChamps(int position, int length) {
this.position = position;
this.length = length;
}
public int getLength() {
return length;
}
public int getPosition() {
return position;
}
private int position;
private int length;
}
```
Voici la classe pour lire et écrire ce fichier :
```java
public class LectureEcriturePersonnes{
public void lecture(File f,File f_out) throws URISyntaxException, FileNotFoundException,
IOException, ParseException {
ReadWriteText lecture;
FileContentText fichier;
// lecture du fichier f
System.out.println("Lecture du fichier " + f.getPath() + " :");
lecture = new ReadWriteText(f,FormatPersonnes.class);
fichier = lecture.readFile();
// affichage du contenu du fichier
fichier.show();
// ecriture du fichier vers f_out
System.out.println("Ecriture du fichier " + f_out.getPath());
lecture.writeFile(f_out, fichier);
}
}
```
Licence
-------
Le code est sous licence [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).