Java/Java 이론
파일 클래스를 이용한 파일 출력
2주녘
2023. 10. 2. 11:37
반응형
* description : File 클래스 : 파일생성 또는 폴더 생성, 정보 보기 기능
public class FileApplication {
public static void main(String[] args) throws Exception {
// TODO : 1) 텍스트 파일을 읽어서 리스트 배열로 가져오기 : Files.readAllLines(Paths.get(경로))
List<String> lines
= Files.readAllLines(Paths.get("src/main/resources/file1.txt"));
System.out.println(lines); // 배열 출력
// TODO : 2) byte 파일을 읽어서 데이터 가져오기
byte[] bytes = Files.readAllBytes(Paths.get("src/main/resources/test1.db"));
System.out.println(Arrays.toString(bytes)); // 결과 출력
}
}
실행결과
[hello, how are you, nice to meet you]
[10, 20, 30]
반응형