Read From File القراءة من ملف نصى

Posted: August 3, 2011 in Java SE


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

package files;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Ahmed Abd El-Rasoul
*/
public class ReadFromFile {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
FileInputStream fis=null;
try {

// Select the name of file using
File f = new File(“ahmed.txt”);
fis = new FileInputStream(f);DataInputStream dis=new DataInputStream(fis);
String s;
while( (s = dis.readLine() ) !=null){
System.out.println(s );
}
}

catch (FileNotFoundException ex) {
Logger.getLogger(ReadFromFile.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ReadFromFile.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(ReadFromFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s