- Development Env.
- post date : 2019. 09. 17
- OS : macOS Majave 64bit
- Java version : JDK 1.8.0 J_220 JRE8
- Eclipse : 2019-06 (4.12.0)
Problem
- 바이트 단위로 비교하기
- 비교값이 틀리면 출력하기
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
30
31
private static final Exception Exception = null;
public static void fileCat() throws IOException{
FileInputStream fis1 = null; FileInputStream fis2 = null;
FileOutputStream fos = null;
try {
fis1 = new FileInputStream("dataProblemInput.txt");
fis2 = new FileInputStream("dataProblemInput2.txt");
fos = new FileOutputStream("fileCatResult.txt");
int readData1 = 0; int readData2 = 0;
while(true){
readData1 = fis1.read();
readData2 = fis2.read();
if(readData1!=readData2||(readData1!=-1&&readData2==-1)) {
System.out.println("불일치~");
throw Exception;
}
if(readData1==-1) {
System.out.println("일치함미당!!!");
break;
}
} catch (Exception e) { e.printStackTrace();
}finally{
try { fos.close();
} catch (IOException e) { e.printStackTrace(); }
try { fis1.close(); fis2.close();
} catch (IOException e) { e.printStackTrace(); }
System.out.println("Cat done");
}
}
같을 경우 결과
1
2
일치함미당!!!
Cat done
같을 경우 결과
1
2
3
4
5
불일치~
Cat done
java.lang.NullPointerException
at chapter17.problem.StringToList.fileCat(StringToList.java:143)
at chapter17.problem.StringToList.main(StringToList.java:33)