1 Mart 2007

Java ile Bir Text Dosyanin Icerigini Okumak

Burada try-catch blogu kullanarak olasi hatalara karsi programi korumus oluyoruz. Eger dosya ile ilgili bir sorun cikarsa, konsola file not found yazacak. Ayrica import java.io.*; eklemeyi unutmayin.

public static void main(String[] args) throws IOException
{
FileInputStream zfile;
try {
zfile = new FileInputStream("c:\\deneme.txt");
} catch(FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
while (zfile.available()>0) {
System.out.print((char) zfile.read());
}
zfile.close();
}

Hiç yorum yok: