문자열 쓰기

// 간단하게 쓰기 위해서 FileWriter 사용

try {
    // 파일 객체 생성
	File file = new File("C:\\\\Users\\\\solst\\\\Desktop\\\\Github\\\\JSP_Practice\\\\Workspace\\\\Login_security\\\\src\\\\main\\\\webapp\\\\SecretKey.txt");
	// 상대경로는 어디 저장되는지 모르겠음
  FileWriter fw = new FileWriter(file);
      
  // 파일안에 문자열 쓰기
	fw.write("첫번째 줄" + '\\n');
  fw.write("두번째 줄");
  fw.flush();
  fw.close();
	out.println("키가 생성되었습니다.");
} catch (IOException e) {
     e.printStackTrace();
}

문자열 읽기

// 한줄한줄 읽기 위해서는 BufferedReader 사용

try {
	BufferedReader reader = new BufferedReader(new FileReader("C:\\\\Users\\\\solst\\\\Desktop\\\\Github\\\\JSP_Practice\\\\Workspace\\\\Login_security\\\\src\\\\main\\\\webapp\\\\SecretKey.txt"));
	String firstLine = reader.readLine();
	String secondLine = reader.readLine();
	// 비밀키 출력
	System.out.println(firstLine);
	System.out.println(secondLine );
	reader.close();
} catch(IOException e) {
	e.printStackTrace();
}