Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 18일차
2024. 12. 11. 17:11ㆍKosta 클라우드 네이티브 어플리케이션 개발(CNA) 교육
package com.lec;
import java.io.File;
import java.text.DecimalFormat;
import java.util.stream.IntStream;
public class chap13_File2 {
public void getDirect(String fileDir) {
File f = new File(fileDir);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
getDirect(files[i].getAbsolutePath());
} else {
// System.out.println(files[i].getName());
}
}
}
public void getDirect2(String fileDir) {
File f = new File(fileDir);
File[] files = f.listFiles();
IntStream.range(0, files.length)
.mapToObj(i -> files[i])
.forEach(file -> {
if (file.isDirectory()) {
getDirect(file.getAbsolutePath());
} else {
// System.out.println(file.getName());
}
});
}
public static void main(String[] args) {
chap13_File2 cf = new chap13_File2();
String fileName = "C:\\IT\\files\\apache-tomcat-9.0.86";
DecimalFormat formatter = new DecimalFormat("###,###");
File f = new File(fileName);
File[] fileArray = f.listFiles();
long startTime = System.nanoTime();
cf.getDirect(fileName);
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("실행 시간: " + duration + "ns");
long startTime2 = System.nanoTime();
cf.getDirect2(fileName);
long endTime2 = System.nanoTime();
long duration2 = endTime2 - startTime2;
System.out.println("실행 시간: " + duration2 + "ns");
}
}
package com.lec;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
public class chap14_IO {
public static void main(String[] args) {
chap14_IO io = new chap14_IO();
// io.io_1();
// io.io_2();
io.io_3();
}
public void io_3() {
String inPath = "C:\\IT\\STS3917\\STS3_WORKSPACE\\pij_java\\src\\com\\lec\\in.txt";
String outPath = "C:\\IT\\STS3917\\STS3_WORKSPACE\\pij_java\\src\\com\\lec\\out.txt";
try {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(inPath)) ;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outPath));
int data = 0;
while ((data = bis.read()) != -1) {
System.out.println(data);
bos.write(data);
}
System.out.println(bos);
bis.close();
bos.close();
} catch(IOException e) {
System.out.println("3번 오류");
}
}
public void io_2() {
String inPath = "C:\\IT\\STS3917\\STS3_WORKSPACE\\pij_java\\src\\com\\lec\\in.txt";
String outPath = "C:\\IT\\STS3917\\STS3_WORKSPACE\\pij_java\\src\\com\\lec\\out.txt";
try {
FileInputStream bais = new FileInputStream(inPath);
FileOutputStream baos = new FileOutputStream(outPath);
int data = 0;
while ((data = bais.read()) != -1) {
System.out.println(data);
baos.write(data);
}
System.out.println(baos);
bais.close();
baos.close();
}catch (FileNotFoundException e) {
System.out.println("2-1번 오류");
}catch (IOException e) {
System.out.println("2-2번 오류");
}
}
public void io_1() {
try {
byte[] inBarr = { 0, 1, 2, 3, 4 };
byte[] outBarr = null;
ByteArrayInputStream bais = new ByteArrayInputStream(inBarr);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int data = 0;
while ((data = bais.read()) != -1) {
System.out.println(data);
baos.write(data);
}
outBarr = baos.toByteArray();
System.out.println(Arrays.toString(outBarr));
bais.close();
baos.close();
} catch (IOException e) {
System.out.println("오류");
}
}
}
'Kosta 클라우드 네이티브 어플리케이션 개발(CNA) 교육' 카테고리의 다른 글
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 20일차 (1) | 2024.12.13 |
---|---|
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 19일차 (2) | 2024.12.12 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 17일차 (0) | 2024.12.10 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 16일차 (1) | 2024.12.09 |
Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 15일차 (1) | 2024.12.06 |