하위링크들

[자바] InputStream과 OutputStream 예제

Quill 2015. 5. 25. 19:27

InputStream예제

public static void main (String[] arg) throws IOException {

try {

InputStream a = new  FileInputStream("C:\\mytext.txt");

while(true){

int i = a.read();

System.out.println("hi : " + i);

if ( i == -1 ) break;

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

OutputStream예제

public static void main (String[] arg) throws IOException {

OutputStream  a = new FileOutputStream("C:\\mytext.txt")  ;

try {

String b = "행복하단. 그런 말을 하고 있었으면서.";

byte[] c = b.getBytes();

a.write(c);

} catch (Exception e) {

// TODO: handle exception

}

} //  메인메소드 닫음


반응형