DateiOperationen

rojaciwan

Grünschnabel
Hallo,

Ich will in einen File Zahlen schreiben aber es geht irgendwie nicht, hat jemand vielleicht einen Tipp

BufferedWriter schreiben = new BufferedWriter(new FileWriter(path,true));
schreiben.write(12344);
schreiben.newLine();
schreiben.close();


Danke
 
Hallo!

Schau mal hier:
Code:
 /**
  * 
  */
 package de.tutorials.training;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 
 /**
  * @author Tom
  * 
  */
 public class NumberToFileWritingExample {
 
 	/**
 	 * @param args
 	 */
 	public static void main(String[] args) throws Exception {
 
 		File binaryFile = new File("c:/numbers.dat");
 
 		DataOutputStream dataOutputStream = new DataOutputStream(
 				new FileOutputStream(binaryFile));
 		dataOutputStream.writeInt(Integer.MAX_VALUE);
 		dataOutputStream.close();
 
 		DataInputStream dataInputStream = new DataInputStream(
 				new FileInputStream(binaryFile));
 		int value = dataInputStream.readInt();
 		dataInputStream.close();
 		System.out.println(value);
 
 		// -----------------------------
 
 		File textFile = new File("c:/numbers.txt");
 		BufferedWriter bw = new BufferedWriter(new FileWriter(textFile));
 		bw.write(String.valueOf(Integer.MAX_VALUE));
 		bw.newLine();
 		bw.close();
 
 		BufferedReader br = new BufferedReader(new FileReader(textFile));
 		String number = br.readLine();
 		br.close();
 		System.out.println(number);
 	}
 
 }

Gruß Tom
 
Zurück