Programmeren in Java/In- & uitvoer: verschil tussen versies

Verwijderde inhoud Toegevoegde inhoud
INVOER - uit een bestand
Regel 109:
}}
 
=Uitvoer=
==byte per byte==
{{Code|
| Taal=Java
| Titel=uitvoer.java
| Code=<source lang=java>import java.io.*;
public class uitvoer {
static String bestandsnaam;
public static void main (String[] args) {
if (args.length != 1){
System.out.println ("Geef bestandsnaam, vb.\n> java uitvoer bestand");
}
else {
if (1 == args.length) {
bestandsnaam = args[0];
char[] letters = {'a', '\t', 'b', '\n', 'c'}; // weg te schrijven data
schrijfBestand(letters);
System.out.println("Weggeschreven naar:\t" + bestandsnaam);
}
}
}
public static void schrijfBestand (char[] w){
try {
bestandsnaam += ".txt";
//een nieuwe file aanmaken
FileOutputStream deLijst = new FileOutputStream(bestandsnaam);
//alle lottocijfers wegschrijven
for (int i=0; i<w.length; i++)
deLijst.write(w[i]);
deLijst.close();
}
catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}</source>
}}
 
<!--
=Uitvoer=
==byte==
==character==
==bestand==
Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.