1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| package Json;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
// création de la fichier json
public class CreateFileJson {
public static void main(String[] args) {
String cheminDuFichier = "C:\\workspace\\laila.json";
String jsonContent = "var links = :[{source: \"10.194.77.251\",target: \"10.194.77.254\"},{source: \"Hack\",target: \"Track\"},{source: \"ad\",target: \"il\"}];";
File file = new File(cheminDuFichier);
System.out.println("le fichier est bien créer");
try {
if (!file.exists())
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(jsonContent);
writer.flush();
writer.close();
} catch (IOException e) {
System.out.println("Erreur: impossible de créer le fichier '"
+ cheminDuFichier + "'");
}
}
} |