Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 전화걸기
- 이클립스
- 배열
- 국제화
- paint
- 메서드
- Graphic
- oracle
- Menu
- layout
- HTML
- mybatis
- JSP
- Eclips
- Java
- 오버로딩
- 메소드
- 에러페이지
- 클래스
- JavaScript
- OGNL
- Spring
- 기본
- 예외처리
- 생성자
- struts2
- Android
- 어노테이션
- 안드로이드
- AWT
Archives
- Today
- Total
note
입출력 파일 생성및 파일 읽기 본문
package com.output; // 입출력으로 파일생성 및 파일 읽기
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class FileOuputstreamEx {
public static void main(String[] args) {
FileOutputStream fos = null;
FileInputStream fin = null;
try{
//파일 생성
fos = new FileOutputStream("c:\\fileout.txt");
//fos = new FileOutputStream("c:\\fileout.txt",true);
//기존 파일이 있으면 이어쓰기함
String message = "Hello File!! 즐거운 하루!!";
//String -> byte[]
//생성된 파일에 데이터 입력
fos.write(message.getBytes());
//존재하는 파일을 읽어드림
fin = new FileInputStream("c:\\fileout.txt");
byte[]b = new byte[fin.available()];
//파일로부터 데이를 읽어드림
fin.read(b);
//byte ->String
//문자열 출력
System.out.println(new String(b));
}catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}catch(IOException ie){
ie.printStackTrace();
}finally{
try{
//스트림을 닫음
if(fos != null) fos.close();
if(fin != null) fin.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
}
Hello File!! 즐거운 하루!!
'자바 > 입출력' 카테고리의 다른 글
Buffer Writer (0) | 2012.01.02 |
---|---|
File Reader (0) | 2012.01.02 |
한줄 단위로 문자열 입력받아 처리하기 (0) | 2012.01.02 |
Buffer사용 (0) | 2012.01.02 |
IO Stream 키보드로 부터 한글자를 입력받아 화면에 출력 (0) | 2012.01.02 |