ComposantsComponents › Fichier › LectureFile › Input
Lit les paires clé/valeur d'un fichier de propriétés Java (.properties) ou d'un fichier .ini et les envoie dans un flux, une ligne par paire, dans les colonnes fixes key et value. En .ini, il lit une section, toutes les sections (avec la colonne section), ou seulement la liste des sections. Pour reprendre des réglages écrits par un autre programme ou par tFileOutputProperties.
Reads the key/value pairs of a Java properties file (.properties) or of an .ini file and sends them into a flow, one row per pair, in the fixed key and value columns. In .ini, it reads one section, all the sections (with the section column), or only the list of the sections. To take back settings written by another program or by tFileOutputProperties.
EntréeInput
Iterate facultatif : aucun flux de données en entrée, le composant commence un sous-joboptional: no data flow in, the component starts a subjob
SortieOutput
Main une ligne par paire (ou par section), nécessaire : sans lien de données, le composant ne fait rienone row per pair (or per section), required: without a data link, the component does nothing
Déclencheurs en sortieOutput triggers
On Subjob Ok On Subjob Error On Component Ok On Component Error Run if
Les colonnes key et value sont celles qu'attend tContextLoad : chaque clé donne sa valeur à la variable de contexte du même nom.
The key and value columns are the ones tContextLoad expects: each key gives its value to the context variable of the same name.
Récupérer tout : une ligne par paire, avec le nom de sa section, pour ranger la configuration dans une table. Retrieve All: one row per pair, with the name of its section, to store the configuration in a table.
.ini, le Mode de récupération et, au besoin, le Nom de section. Le schéma suit ce choix ; il est en lecture seule.
Choose the File Format; in .ini, the Retrieve Mode and, if needed, the Section Name. The schema follows this choice; it is read-only.
.ini, l'Encodage dans les paramètres avancés (ISO-8859-15 par défaut).
Set the File Name and, for an .ini, the Encoding in the advanced settings (ISO-8859-15 by default).
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| SchémaSchemaSCHEMA | key, value |
ToujoursAlways |
En lecture seule, colonnes String selon le format et le mode : key, value en .properties et par section ; key, value, section pour tout le .ini ; section seule pour la liste des sections.
Read-only, String columns depending on the format and the mode: key, value in .properties and by section; key, value, section for the whole .ini; section alone for the list of the sections.
|
| Format de fichierFile FormatFILE_FORMAT | .properties |
ToujoursAlways |
.properties : lu par java.util.Properties : séparateur =, : ou espace, commentaires # et !, ligne continuée par \, caractères \uXXXX ; les clés sortent dans un ordre quelconque (voir l'exemple). .ini : lu par la bibliothèque ini4j 0.5.1, des lignes clé = valeur sous des titres [section], dans l'ordre du fichier.
.properties: read by java.util.Properties: =, : or space separator, # and ! comments, line continued with \, \uXXXX characters; the keys come out in any order (see the example). .ini: read by the ini4j 0.5.1 library, key = value lines under [section] titles, in the order of the file.
|
| Mode de récupérationRetrieve ModeRETRIVE_MODE | Récupérer par sectionRetrieve By Section | Format .ini.ini format |
Récupérer tout : toutes les paires de toutes les sections, avec la colonne section. Récupérer des sections : une ligne par section, son nom seulement. Récupérer par section : les paires de la section nommée ci-dessous (voir les exemples).
Retrieve All: all the pairs of all the sections, with the section column. Retrieve Sections: one row per section, its name only. Retrieve By Section: the pairs of the section named below (see the examples).
|
| Nom de sectionSection NameSECTION_NAME | "section" |
Format .ini et récupérer par section.ini format and retrieve by section |
La section lue, en expression Java, sans les crochets : "database". Une section absente ne donne aucune ligne, sans erreur.
The section read, as a Java expression, without the brackets: "database". A missing section gives no row, with no error.
|
| Nom de fichierFile NameFILENAME | chemin par défaut + /in.propertiesdefault path + /in.properties |
ToujoursAlways |
Le fichier lu, en expression Java : context.folder + "/app.properties". Un fichier absent arrête le job, sans réglage pour l'éviter (voir les erreurs).
The file read, as a Java expression: context.folder + "/app.properties". A missing file stops the job, with no setting to avoid it (see the errors).
|
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| EncodageEncodingENCODING | "ISO-8859-15" |
ToujoursAlways |
.ini seulement : l'encodage du fichier (voir l'exemple). En .properties, il est sans effet : le fichier est toujours lu en ISO-8859-1 (voir le défaut).
.ini only: the encoding of the file (see the example). In .properties, it has no effect: the file is always read as ISO-8859-1 (see the flaw).
|
NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes envoyées, une par paire (ou par section avec Récupérer des sections). Sans lien de données, le composant n'est pas généré : NB_LINE vaut null.
NB_LINE (Integer, available after the component has run): number of rows sent, one per pair (or per section with Retrieve Sections). Without a data link, the component is not generated: NB_LINE is null.
System.out.println("NB_LINE: " + globalMap.get("tFileInputProperties_1_NB_LINE"));
Les fichiers sont lus dans le dossier de la variable de contexte folder, écrits en UTF-8. Les lignes vont à un tLogRow en mode tableau ; un tJava relié par On Subjob Ok affiche ensuite NB_LINE. Les sorties sont celles de la console, copiées depuis une exécution du job.
The files are read in the folder of the folder context variable, written in UTF-8. The rows go to a tLogRow in table mode; a tJava connected with On Subjob Ok then prints NB_LINE. The outputs are the console ones, copied from a run of the job.
app.properties, réglages par défaut :
app.properties, default settings:
# Settings of the application
db.host=localhost
db.port : 5432
db.url=jdbc\:postgresql\://db01\:5432/app
app.title=Caf\u00e9 cr\u00e8me
app.city=Montréal
app.list=one, \
two, \
three
! old style comment
empty=
.---------+-------------------------------. | tLogRow_1 | |=--------+------------------------------=| |key |value | |=--------+------------------------------=| |app.list |one, two, three | |db.port |5432 | |db.url |jdbc:postgresql://db01:5432/app| |app.city |Montréal | |db.host |localhost | |empty | | |app.title|Café crème | '---------+-------------------------------' NB_LINE: 7
: sert de séparateur, \: redevient :, les trois lignes de app.list n'en font qu'une, \u00e9 devient é, empty a une valeur vide (pas null).
: is a separator, \: becomes : again, the three lines of app.list make only one, \u00e9 becomes é, empty has an empty value (not null).
é écrit en UTF-8 dans Montréal est lu comme deux caractères.
The é written in UTF-8 in Montréal is read as two characters.
Défaut du modèle : l'encodage est ignoré en .properties. Le même job avec l'Encodage "UTF-8" donne exactement la même sortie, Montréal compris : le modèle charge le fichier par Properties.load(InputStream), toujours en ISO-8859-1 (tFileInputProperties_begin.javajet). Écrivez les caractères non ASCII en \uXXXX, comme le fait tFileOutputProperties, ou convertissez le fichier en ISO-8859-1 avant de le lire.
Template flaw: the encoding is ignored in .properties. The same job with the Encoding "UTF-8" gives exactly the same output, Montréal included: the template loads the file with Properties.load(InputStream), always as ISO-8859-1 (tFileInputProperties_begin.javajet). Write the non-ASCII characters as \uXXXX, as tFileOutputProperties does, or convert the file to ISO-8859-1 before reading it.
app.ini ; Format de fichier .ini, Encodage "UTF-8" :
app.ini; File Format .ini, Encoding "UTF-8":
; Settings of the application
[database]
host = db01
port = 5432
title = Café crème
[ui]
lang = fr
# theme of the screens
theme = dark
Récupérer toutRetrieve All
.-----+----------+--------. | tLogRow_1 | |=----+----------+-------=| |key |value |section | |=----+----------+-------=| |host |db01 |database| |port |5432 |database| |title|Café crème|database| |lang |fr |ui | |theme|dark |ui | '-----+----------+--------' NB_LINE: 5
Récupérer des sectionsRetrieve Sections
.--------. |tLogRow_1| |=------=| |section | |=------=| |database| |ui | '--------' NB_LINE: 2
Récupérer par section, "database"Retrieve By Section, "database"
.-----+----------. | tLogRow_1 | |=----+---------=| |key |value | |=----+---------=| |host |db01 | |port |5432 | |title|Café crème| '-----+----------' NB_LINE: 3
Avec le nom "missing" : aucune ligne, NB_LINE: 0, sans message. Les commentaires ; et # et la ligne vide sont sautés.
With the name "missing": no row, NB_LINE: 0, with no message. The ; and # comments and the empty line are skipped.
Le même app.ini, section "database", Encodage laissé à "ISO-8859-15" :
The same app.ini, section "database", Encoding left at "ISO-8859-15":
.-----+------------. | tLogRow_1 | |=----+-----------=| |key |value | |=----+-----------=| |host |db01 | |port |5432 | |title|Café crÚme| '-----+------------'
Chaque caractère accentué, deux octets en UTF-8, devient deux caractères ISO-8859-15. Each accented character, two bytes in UTF-8, becomes two ISO-8859-15 characters.
orphan.ini, Récupérer tout :
orphan.ini, Retrieve All:
orphan = 1
[s]
a = 1
.------+-----+-------. | tLogRow_1 | |=-----+-----+------=| |key |value|section| |=-----+-----+------=| |orphan|1 |? | |a |1 |s | '------+-----+-------' NB_LINE: 2
La clé hors section est rangée dans une section nommée ?, qui apparaît aussi avec Récupérer des sections.
The key outside any section is put in a section named ?, which also shows with Retrieve Sections.
quirks.ini, section "s", encodage par défaut :
quirks.ini, section "s", default encoding:
[s]
a = 1
a = 2
b = "quoted"
c = x\ty
d = C:\temp\new
e = 50% ; discount
f =
.---+--------------. | tLogRow_1 | |=--+-------------=| |key|value | |=--+-------------=| |a |2 | |b |"quoted" | |c |x\ty | |d |C:\temp\new | |e |50% ; discount| |f | | '---+--------------' NB_LINE: 6
\t et \n ne sont pas interprétés (un tJavaRow qui affiche les codes des caractères ne trouve ni tabulation ni fin de ligne) : un chemin Windows est lu tel quel.
The quotes stay in the value; \t and \n are not interpreted (a tJavaRow that prints the character codes finds no tab and no line end): a Windows path is read as is.
; après la valeur n'est pas un commentaire : il en fait partie.
A ; after the value is not a comment: it belongs to it.
Le nom du job est remplacé par MyJob, le dossier des fichiers par C:\data ; la trace d'exception est abrégée. La fin du message vient de Windows, dans sa langue.
The job name is replaced with MyJob, the folder of the files with C:\data; the exception trace is shortened. The end of the message comes from Windows, in its language.
missing.properties n'existe pas : le job s'arrête (code 1). Le message est le même en .ini.
missing.properties does not exist: the job stops (exit code 1). The message is the same in .ini.
Exception in component tFileInputProperties_1 (MyJob) java.io.FileNotFoundException: C:\data\missing.properties (Le fichier spécifié est introuvable) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:213) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:152) …
Le composant n'a pas d'option pour continuer sans fichier. Si le fichier est facultatif, testez-le avant avec tFileExist et un lien Run if. The component has no option to go on without the file. If the file is optional, test it before with tFileExist and a Run if link.
Les paires d'un .properties sortent dans l'ordre interne de Java, pas dans celui du fichier, et il peut changer avec les clés. Si l'ordre compte, triez les lignes après le composant ; un .ini garde l'ordre du fichier.
The pairs of a .properties come out in the internal order of Java, not in the order of the file, and it may change with the keys. If the order matters, sort the rows after the component; an .ini keeps the order of the file.
Relié seulement par des déclencheurs (On Subjob Ok…), le composant n'est pas généré : il ne lit pas le fichier, ne signale pas son absence, et NB_LINE vaut null. Il lui faut une sortie Main, ou une entrée Iterate.
Connected only with triggers (On Subjob Ok…), the component is not generated: it does not read the file, does not report it missing, and NB_LINE is null. It needs a Main output, or an Iterate input.
En .properties, écrivez les caractères non ASCII en \uXXXX : le fichier est toujours lu en ISO-8859-1. En .ini, réglez l'Encodage sur celui du fichier.
In .properties, write the non-ASCII characters as \uXXXX: the file is always read as ISO-8859-1. In .ini, set the Encoding to that of the file.
Une clé répétée ne garde que sa dernière valeur (règle d'ini4j comme de java.util.Properties). Pour lire toutes les lignes d'un fichier, même répétées, lisez-le plutôt avec tFileInputRegex, qui donne une ligne de sortie par ligne reconnue.
A repeated key only keeps its last value (rule of ini4j as of java.util.Properties). To read all the lines of a file, even repeated, read it instead with tFileInputRegex, which gives one output row per recognized line.
tFileOutputProperties · écrire un fichier .properties ou .iniwrite a .properties or .ini filetContextLoad · charger les paires lues dans le contexteload the pairs read into the contexttContextDump · sortir le contexte en paires clé/valeuroutput the context as key/value pairstFileInputDelimited · lire un fichier à séparateursread a delimited filetFileExist · tester le fichier avant de le liretest the file before reading ittChangeFileEncoding · convertir le fichier avant de le lireconvert the file before reading it