📌 스트림(Stream)
: 데이터가 이동하는 통로분류
- InputStream : 입력스트림
- OutputStream : 출력스트림
데이터 종류에 따른 분류
- 바이트스트림
- 문자스트림
✅ 수업예문
FileReader & FileWriter
💻 code
String path = "src/fileReader.txt"; String destinationPath = "src/fileWriter.txt"; File file = new File(path); FileReader reader = null; FileWriter writer = null; try { reader = new FileReader(path); writer = new FileWriter(destinationPath, true); int input = 0; while((input = reader.read()) != -1) { writer.write(input); } writer.write('\n'); } catch (IOException e) { e.printStackTrace(); } finally { try{ if(writer != null) writer.close(); if(reader != null) writer.close(); } catch(IOException e) {} }
FileWriter(String name, boolean append)
:append가 true면 기존 데이터에 이어쓰기 false면 새로 쓰기
** append는 생략가능 (기본값 false)new File
파일을 생성하는게 아니라 파일을 다루는 객체를 생성- 닫을때는
(FileWriter)outputStream
먼저 닫아줌