728x90
반응형
FileInputStream - https://sungwoon.tistory.com/88
FileOutputStream - https://sungwoon.tistory.com/89
import java.io.*;
public class FileExam {
public static void main(String[] args) throws IOException {
File f = new File("/Users/test.sh");
File f2 = new File("/Users/test2.sh");
System.out.println("f.getAbsolutePath() = " + f.getAbsolutePath());
if(!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
}
if (!f.exists()) {
f.createNewFile();
}
InputStream is = new FileInputStream(f);
OutputStream os = new FileOutputStream(f2);
int data = 0;
// file read and write
while((data = is.read()) != -1) {
char c = (char)data;
os.write(c);
}
is.close();
os.close();
}
}
728x90
반응형
'Programming > Java' 카테고리의 다른 글
[Java]File Write/쓰기 (OutputStream/BufferedOutputStream) (0) | 2024.06.08 |
---|---|
[Java]File 읽기/Read (FileInputStream, BufferedInputStream) (0) | 2024.06.08 |
Causes of getting a java.lang.VerifyError (0) | 2024.05.28 |
[Java-자바]인터페이스(interface) (0) | 2017.02.05 |
[Java-자바]추상 클래스 및 추상 메서드(abstract class and abstract method) (1) | 2017.02.04 |