Merhaba arkadaşlar aşagıda javada dosyadan okuma ve yazma işlemlerinin kodu verilmiştir.

Kolay gelsin

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package UygulamaDers4.DosyaIslemleri;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author RamazanCEsur
*/
public class Dosya {

public boolean dosyayaYaz(String yazi, String myFile){
boolean geri = true;
FileWriter fwriter;
BufferedWriter bw = null;
try {
fwriter = new FileWriter(myFile, true);
bw = new BufferedWriter(fwriter);
bw.write(yazi + “t”);
} catch (Exception ex) {
System.out.println(“Yazarken oluşan hata = ” + ex.toString());
geri = false;
} finally {
try {
bw.close();
} catch (IOException ex) {
Logger.getLogger(Dosya.class.getName()).log(Level.SEVERE, null, ex);
}
}
return geri;
}

public String dosyadanOku(String myFile) {
String tmp=””;
BufferedReader reader = null;
FileReader freader = null;
try {
freader = new FileReader(myFile);
reader = new BufferedReader(freader);
String satir = reader.readLine();
tmp+=satir;
while (satir != null) {
//System.out.println(satir);
satir = reader.readLine();
tmp+=satir;
}
} catch (Exception ex) {
//System.out.println(“Okurken oluşan hata = ” + ex.toString());
} finally {
try {
reader.close();
} catch (IOException ex) {
Logger.getLogger(Dosya.class.getName()).log(Level.SEVERE, null, ex);
}
}
return tmp;
}

public void dosyadanOkuNew(String myFile) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(myFile));
String satir = reader.readLine();
while (satir != null) {
System.out.println(satir);
satir = reader.readLine();
}
} catch (Exception ex) {
System.out.println(“Okurken oluşan hata = ” + ex.toString());
} finally {
reader.close();
}
}

public void dosyadanOkuNewFor(String myFile) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(myFile));
String satir = reader.readLine();
for (int i = 1; i > 0; i++) {

if (satir != null) {
System.out.println(satir);
}

if (satir == null) {
i = -10;
}

satir = reader.readLine();
}
} catch (Exception ex) {
System.out.println(“Okurken oluşan hata = ” + ex.toString());
} finally {
reader.close();
}
}
}

Ramazan Cesur…