Hier ein kleines Beispiel um in Java Daten in eine Datei zu schreiben:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileClass {

public static void main(String[] args)
{

try {

File file = new File(„C:\\WINDOWS\\Temp\\subdirectory\\file.txt“);
// create directory and file if it does not exist
if (!file.exists()) {

// create directory if the directory does not exist
new File(„C:\\WINDOWS\\Temp\\subdirectory“).mkdirs();
file.createNewFile();

}
FileOutputStream stream = new FileOutputStream(file);
// write data to file
stream.write(„Test“.getBytes());
// empty data puffer
stream.flush();
// close output stream
stream.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

 Antworten

   
Impressum Suffusion theme by Sayontan Sinha