Skip to content

Commit 9071508

Browse files
committed
update the package practice.io
1 parent af14f21 commit 9071508

File tree

6 files changed

+58
-18
lines changed

6 files changed

+58
-18
lines changed

.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_201">
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_202">
55
<attributes>
66
<attribute name="owner.project.facets" value="java"/>
77
</attributes>

copied.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�Ӽ���!�Դϴ�

hello_world_copy.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
�Ӽ���!�Դϴ�.
1+
�Ӽ���!�Դϴ�

src/practice/io/FileLoaderClass.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ public void read() {
2121
in = new FileInputStream(path);
2222
int data = 0;
2323

24-
while (true) {
25-
try {
26-
// 파일 읽기
27-
data = in.read();
28-
if(data == -1) break;
29-
System.out.println("data: " + data);
30-
31-
} catch (IOException e) {
32-
e.printStackTrace();
24+
try {
25+
while (data != -1) {
26+
// 파일 읽기
27+
data = in.read();
28+
System.out.println("data: " + data);
3329
}
30+
} catch (IOException e) {
31+
e.printStackTrace();
3432
}
35-
33+
3634
} catch (FileNotFoundException e) {
3735
e.printStackTrace();
3836
} finally {

src/practice/io/FileWriterClass.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void write(String data) {
2323
try {
2424
// 데이터 쓰기
2525
out.write(data.getBytes(), 0, data.getBytes().length);
26+
// out.write(-1); // FileOutputStream.write(FileInputStream.read())로 응용 가능하다
2627
} catch (IOException e) {
2728
e.printStackTrace();
2829
}

src/practice/io/MainClass.java

+46-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,62 @@
11
package practice.io;
22

3-
import java.io.*;
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintStream;
7+
import java.io.PrintWriter;
48

59
public class MainClass {
610

711
public static void main(String[] args) throws IOException {
812

9-
/*
1013
String path = "E:\\eclipse-workspace\\Webtest\\hello_world_copy.txt";
14+
byte[] buffer = new byte[512];
15+
16+
// ---
17+
/*
18+
FileInputStream fis = new FileInputStream(path);
19+
FileOutputStream fos = new FileOutputStream("copied.txt");
20+
21+
// read()가 argument를 받지 않으면 개별 문자의 byte를 반환한다
22+
// int data = 0;
23+
// while ( (data = fis.read()) != -1 ) {
24+
// fos.write(data);
25+
26+
// read()가 argument를 받으면 argument의 length 내에서 총 몇 byte나 차지하는지를 반환한다
27+
int dataCount = 0;
28+
while ( (dataCount = fis.read(buffer)) != -1 ) {
29+
fos.write(buffer, 0, dataCount);
30+
}
31+
fos.close();
32+
fis.close();
33+
*/
34+
// ---
35+
36+
PrintStream ps = System.out;
37+
PrintWriter pw2 = new PrintWriter(ps);
38+
pw2.println("ddd");
1139

12-
FileLoader fl = new FileLoader("E:\\eclipse-workspace\\Webtest\\hello_world.txt");
13-
byte[] b = new byte[3];
40+
// ---
41+
42+
BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
43+
String str = br2.readLine();
44+
System.out.println(str);
45+
46+
// pw2.close();
47+
br2.close();
48+
49+
// ---
50+
/*
51+
FileLoaderClass fl = new FileLoaderClass("E:\\eclipse-workspace\\Webtest\\hello_world.txt");
1452
1553
fl.read();
1654
1755
// ---
1856
19-
FileWriter fw = new FileWriter(path);
57+
FileWriterClass fw = new FileWriterClass(path);
2058
21-
fw.write("임세진!입니다.");
59+
fw.write("임세진!입니다");
2260
2361
// ---
2462
@@ -45,6 +83,7 @@ public static void main(String[] args) throws IOException {
4583

4684
// ---
4785

86+
/*
4887
String path_to_load = ".\\testFile.txt";
4988
String path_to_save = ".\\testFile_copy.txt";
5089
@@ -60,6 +99,7 @@ public static void main(String[] args) throws IOException {
6099
File file = new File(".");
61100
String absolutePath = file.getAbsolutePath();
62101
System.out.println(absolutePath);
102+
*/
63103

64104
// ---
65105

0 commit comments

Comments
 (0)