Files
DEV/DEV2.1/CM2/Prototype.java

49 lines
1.2 KiB
Java
Raw Permalink Normal View History

2024-05-17 10:59:23 +02:00
//Patrick Felix-Vimalaratnam
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
public class Prototype{
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("Manque le nom du fichier");
System.exit(1);
}
String nom = new String();
for (int i=0; i<args.length; i++){
nom=nom+args[i];
}
File f = new File(nom);
try{
f.createNewFile();
try{
FileOutputStream ecrit = new FileOutputStream(f);
String chaine = new String();
String ouvrant =new String();
String fermant =new String();
String espace =new String();
chaine = "public class";
ouvrant = "{";
fermant = "}";
espace = " ";
ecrit.write(chaine.getBytes());
ecrit.write(espace.getBytes());
ecrit.write(nom.getBytes());
ecrit.write(espace.getBytes());
ecrit.write(ouvrant.getBytes());
ecrit.write(espace.getBytes());
ecrit.write(fermant.getBytes());
try{
ecrit.close();
}catch(IOException e){
System.err.println("Erreur fermeture");
}
}catch(IOException e){
System.err.println("Erreur ecriture");
}
}catch(IOException e){
System.err.println("Erreur d'ouverture");
}
}
}