'file i/o'에 해당되는 글 1건
[04.30] 수업 내용 :: 2007/04/30 11:33
1. FILE I/O - exam1
more..
2. exam2
more..
3. exam3
more..
4. exam4
more..
5. exam5
more..
6. exam6
more..
7. exam7
more..
8. exam8
more..

| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 |
1. FILE I/O - exam1
more..
import java.io.*;
public class Exam_05 {
public static void main(String[] args) throws IOException {
FileOutputStream fos1 = new FileOutputStream(FileDescriptor.out);
File f = new File("aaa.txt");
FileOutputStream fos2 = new FileOutputStream(f);
byte [] by = new byte[]{'H', 'e', 'l', 'l', 'o', ' ', 'J', 'a', 'v', 'a'};
// System.out.println("Hello Java");
fos1.write(by);
fos2.write(by);
fos2.flush();
fos1.close();
fos2.close();
}
}
2. exam2
more..
import java.io.*;
public class Exam_06 {
public static void main(String ... arg) throws IOException {
FileOutputStream fos1 = new FileOutputStream(new File("bbb.txt"), false);
BufferedOutputStream bos1 = new BufferedOutputStream(fos1);
DataOutputStream dos1 = new DataOutputStream(bos1);
dos1.writeInt(20);
dos1.writeDouble(12.34);
dos1.flush();
dos1.writeChar('A');
dos1.writeByte('\n');
dos1.writeByte('B');
dos1.close();
}
}
3. exam3
more..
import java.io.*;
public class Exam_07 {
public static void main(String[] args) throws IOException {
FileInputStream fis1 = new FileInputStream(FileDescriptor.in);
System.out.print("문자 : ");
char ch = (char)fis1.read();
System.in.read(); // Enter나 마찬가지(문자를 입력을 끝내겠다는 뜻)
System.out.print("문자열 : ");
byte [] by = new byte[1024];
fis1.read(by);
System.out.printf("\nch : %c\nby : %s", ch, new String(by).trim());
fis1.close();
}
}
4. exam4
more..
import java.io.*;
public class Exam_07_1 {
public static void main(String[] args) throws IOException {
FileInputStream fis2 = new FileInputStream(new File("aaa.txt"));
int x = -1;
while((x = fis2.read()) != -1)
System.out.print((char)x);
fis2.close();
}
}
5. exam5
more..
import java.io.*;
public class Exam_08 {
public static void main(String[] args) throws IOException {
// 그냥 장난 쳐본거~!
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(new File("bbb.txt"))));
int a = dis.readInt();
double b = dis.readDouble();
char c = dis.readChar();
byte d = dis.readByte();
byte e= dis.readByte();
dis.close();
System.out.printf("a = %d\nb = %f\nc = %c\nd = %d\ne = %c", a, b, c, d, (char)e);
}
}
6. exam6
more..
import java.io.*;
public class Exam_08_1 {
public static void main(String[] args) throws IOException {
// 그냥 장난 쳐본거~!
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(new File("bbb.txt"))));
int x = -1;
while((x = dis.read()) != -1)
System.out.print((char)x);
dis.close();
}
}
7. exam7
more..
import java.io.*;
public class Exam_09 {
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(System.out);
BufferedWriter bw = new BufferedWriter(osw);
PrintWriter pw = new PrintWriter(bw);
pw.println(10);
pw.println("test 안녕하세요~");
pw.close();
}
}
8. exam8
more..