Input Output Stream

Rabu, 16 November 2011

INPUT STREAM:
public class TestFileInputStream {


    public static void main(String[] args) throws FileNotFoundException, IOException {
        // buat file
        File test = new File("latih.txt");
        // buat stream
        FileInputStream in = new FileInputStream(test);
        // baca stream
        String result = new String();
        int c;
        while ((c = in.read()) != -1) {
            result = result + (char) c;
        }
        // tutup stream
        in.close();


        System.out.println("result " + result);


    }
}




INPUT STREAM:

public class TestFileOutputStream {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // buat file
        File test = new File("latih.txt");
        // buat stream
        FileOutputStream out = new FileOutputStream(test);
        // tulis stream
        String data = "hello world";
        out.write(data.getBytes());
        // tutup stream
        out.close();
    }
}

Get This Comment Form

0 comment(s):

 
Copyright© 2010 Felisitas Brillianti | Semelekete Weleh Weleh | http://dr214ac.blogspot.com