Reading a file

package readfile;

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

/**
 *
 * @author nurhak.kaya
 */
public class ReadFile {

    public static void main(String[] args) {
        File file = new File("text.txt");
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;
        String text = null;

        try {
            br = new BufferedReader(new FileReader(file));

            while ((text = br.readLine()) != null) {
                sb.append(text).append(
                        System.getProperty("line.separator"));
                System.out.println(text);

            }

        } catch (Exception e) {
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException ex) {
                    Logger.getLogger(ReadFile.class.getName()).log(
                            Level.SEVERE, null, ex);
                }

            }
        }
    }
}

Comments

  1. Hayatın özünü kodlara yazıp yansıttığınız bu veciz blogunuz hayırlı uğurlu olsun...muhabbetle

    ReplyDelete

Post a Comment

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"