Back-End23 File I/O : FileInputStream, BufferedReader 이전 포스팅에서 쓰기를 해봤으니 읽기를 해보려고 한다. import java.io.FileInputStream; import java.io.IOException; public class FileRead { public static void main(String[] args) throws IOException { byte[] b = new byte[1024]; FileInputStream input = new FileInputStream("c:/out.txt"); input.read(b); System.out.println(new String(b)); input.close(); } } 1024byte 단위로 읽어오게 되는데, InputStream에 b를 저장했다가 출력하는 방식이다. 다만 정확한 길이를 모.. 2021. 4. 2. File I/O : FileWriter 로 내용 추가하기 먼저 코드를 보겠다. import java.io.FileWriter; import java.io.IOException; public class FileWrite { public static void main(String[] args) throws IOException { FileWriter fw2 = new FileWriter("c:/out.txt", true); for(int i=11; i 2021. 4. 2. File I/O : FileWriter, PrintWriter 이전에 배운 FileOutputStream 의 경우 Byte 단위로 출력해야 한다. 경량의 데이터로 Byte로 출력해야 하는 경우도 있겠지만 보통은 String 이 출력의 대상이 되지 않을까 한다. String으로 출력하는 데는 두 가지 방법이 있다. 먼저 FileWriter. import java.io.FileWriter; import java.io.IOException; public class FileWrite { public static void main(String[] args) throws IOException { FileWriter fw = new FileWriter("c:/out.txt"); for(int i=1; i 2021. 4. 2. File I/O : FileOutputStream Java를 학습한 지 적어도 4개월이 지난 것 같습니다. 그 중 File I/O에 대한 부분이 기억이 나지 않는데, 앞으로 입사할 회사에서 사용할 것 같은 부분을 개인적으로 공부해보려 합니다. 가장 기초적인 것으로 FileOutputStream을 이용해서 txt파일로 출력해보겠습니다. public class FileTest { public static void main(String[] args) throws IOException { test(); } public static void test() throws IOException{ FileOutputStream out = new FileOutputStream("C:/Users/sksya/Desktop/out.txt"); for (int i = 0; i <.. 2021. 4. 1. 이전 1 2 3 4 5 6 다음