lang:csharp:readerwriter
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| lang:csharp:readerwriter [2017/05/18 15:03] – [Ajout d'un texte à l'intérieur d'une fichier] : orthographe root | lang:csharp:readerwriter [2020/04/27 08:04] (Version actuelle) – Conversion de <note> vers <WRAP> root | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| Il faut utiliser '' | Il faut utiliser '' | ||
| - | =====BinaryWriter===== | + | =====BinaryReader / BinaryWriter===== |
| <code csharp> | <code csharp> | ||
| using (BinaryWriter bw = new BinaryWriter(File.Open(fichier, | using (BinaryWriter bw = new BinaryWriter(File.Open(fichier, | ||
| </ | </ | ||
| + | |||
| + | Pour info, il est possible de faire un '' | ||
| + | |||
| + | '' | ||
| =====Lecture de 5 octets sous forme d'un string===== | =====Lecture de 5 octets sous forme d'un string===== | ||
| Ligne 16: | Ligne 20: | ||
| string result = System.Text.Encoding.ASCII.GetString(lecture); | string result = System.Text.Encoding.ASCII.GetString(lecture); | ||
| </ | </ | ||
| - | Apparemment, | + | |
| + | Il n'y a pas besoin du caractère '' | ||
| + | |||
| + | <WRAP center round info 60%> | ||
| + | Par contre, cette méthode crée un '' | ||
| + | <code csharp> | ||
| + | if (result.IndexOf(' | ||
| + | { | ||
| + | result = result.Substring(0, | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| =====Remplacement dans un fichier via regex/ | =====Remplacement dans un fichier via regex/ | ||
| Ligne 29: | Ligne 44: | ||
| { | { | ||
| string tempLineValue; | string tempLineValue; | ||
| - | | + | FileStream inputStream = null; |
| + | try | ||
| { | { | ||
| + | inputStream = File.OpenRead(originalFile) | ||
| using (StreamReader inputReader = new StreamReader(inputStream)) | using (StreamReader inputReader = new StreamReader(inputStream)) | ||
| { | { | ||
| + | inputStream = null; | ||
| using (StreamWriter outputWriter = File.AppendText(outputFile)) | using (StreamWriter outputWriter = File.AppendText(outputFile)) | ||
| { | { | ||
| Ligne 41: | Ligne 59: | ||
| } | } | ||
| } | } | ||
| + | } | ||
| + | finally | ||
| + | { | ||
| + | if (inputStream != null) | ||
| + | inputStream.Dispose(); | ||
| } | } | ||
| } | } | ||
| </ | </ | ||
| - | [[http:// | + | [[https:// |
| + | [[https:// | ||
| =====Ajout d'un texte à l' | =====Ajout d'un texte à l' | ||
| Pas de méthode miracle malheureusement. | Pas de méthode miracle malheureusement. | ||
| Ligne 70: | Ligne 94: | ||
| </ | </ | ||
| - | [[http:// | + | [[https:// |
| =====Chargement d'un fichier texte en mémoire===== | =====Chargement d'un fichier texte en mémoire===== | ||
| Ligne 85: | Ligne 109: | ||
| </ | </ | ||
| - | [[http:// | + | [[https:// |
lang/csharp/readerwriter.1495112604.txt.gz · Dernière modification : de root
