Hier ein Beispiel wie man mit Java aus einer Datei Daten auslesen kann:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileClass {

public static void main(String[] args) {

try {

File file = new File(„C:\\WINDOWS\\Temp\\subdirectory\\file.txt“);

// read data from file
BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String s = input.readLine();

// close reader
input.close();

// write data to stdout
System.out.println(„Result: “ + s);

} catch (IOException e) {

e.printStackTrace();

}

}

}

 

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();

}

}

}

Impressum Suffusion theme by Sayontan Sinha