package kh.java.test;
import java.awt.event.FocusAdapter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Scanner;
public class Exam {
Scanner sc = new Scanner(System.in);
public void primaryStream() {
System.out.print("저장할 파일명 입력 : ");
FileOutputStream fos=null;
String fileName = sc.next();
sc.nextLine();
try {//입력받은 파일명으로 파일아웃풋 스트림 생성
fos = new FileOutputStream(fileName);//try~catch쓰라고되어있다.
//"test.txt라고 저장할수도있다.fileName대신써도된다."
System.out.println("'"+fileName+"'파일에 저장될 내용");
System.out.println("종료는 exit");
int lineNumber=1;//몇번째줄에 글씨를 입력하고있는지 체크하기 위한변수이다.
while(true) {
System.out.print((lineNumber++)+":");
String str = sc.nextLine()+"\r\n";//실제로 입력하는구간
//\r\n이 줄끝났어 라고 붙여준것이다.
//\r은 캐럿이 그 줄 맨 앞으로 갑니다.
//(Carriage return)
//\n은 캐럿이 다음 줄로 갑니다.
//(Line feed)
//의미가 여기서 끝내고 다음줄로 넘어가라는 의미이다.입력후다음줄가라.
//sc.nextLine();
if(str.equals("exit\r\n")) {//exit들어오면 더이상 코드수행하지않고 종료해라
break;
}else {
fos.write(str.getBytes());
//쓰기 메소드를 통해서 쓸것이다.문자를 byte형태로 내보낸다.
}
}
}catch(FileNotFoundException e) {
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
fos.close();
} catch (Exception e2) {
// TODO: handle exception
}
}//닫아주는 코드이다
//FOS로 해서 자동완성 쓰기
}
}
'IT일반과목 > java' 카테고리의 다른 글
16진수 10진수 바꾸는 코드 (0) | 2018.08.07 |
---|---|
글자텍스트를 그림으로 바꾸기 inOUT실습 (0) | 2018.08.07 |
memberShipProject (1) | 2018.08.06 |
자바 콜렉션(실습) - 로또 (0) | 2018.08.06 |
자바 콜렉션(수업)-3 (0) | 2018.08.06 |