Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 예제
- 스택
- 서블릿
- java
- 자바
- 서블릿 파라미터
- 객체
- DA#
- File
- 오라클
- 설치방법
- 서블릿 동작방식
- 자바 암호화
- 테이블 설계
- Servlet
- 컨텍스트 초기화 객체
- 숫자야구
- OOP
- 자바객체
- 자바공부
- 자바I/O
- 자바기초
- 자바문제
- SQL
- 입출력
- 서블릿 값 가져오기
- 스트림
- 자바설치
- 서블릿 예제
- 조건문
Archives
- Today
- Total
다양한 관심 :)
Java- File 객체 만들기 본문
File 객체 만들기 연습
1. new File(String 파일 또는 경로 );
==>디렉토리와 디렉토리 사이 또는 디렉토리와 파일 명 사이의 구분문자는
'/'(슬레쉬) 를 사용하거나 역슬레쉬를 사용할 수 있다.
// File file1 = new File("D:/D_Other/test.txt"); : 구분 문자로 '/' 사용한 경우
File file1 = new File("D:\\D_Other\\test.txt"); // : 구분 문자로 '\\' 사용한 경우
System.out.println(" 파일 명 : " + file1.getName());
System.out.println("디렉토리인지 검사 ");
System.out.println(" 디렉토리 일까 ? " + file1.isDirectory());
System.out.println(" 파일 일까 ? " + file1.isFile());
System.out.println();
- new File( 경로까지만 설정)
File file2 = new File("d:/d_other");
System.out.println(" 파일 명 : " + file2.getName());
System.out.println("디렉토리인지 검사 ");
System.out.println(" 디렉토리 일까 ? " + file2.isDirectory());
System.out.println(" 파일 일까 ? " + file2.isFile());
System.out.println();
2. new File(File parent, String child)
==> 'parent' 디렉토리안에 있는 'child' 파일을 나타낸다.
// file2 - 디렉토리를 갖는 파일 객체를 넣어줌 = d:/d_other
File file3 = new File(file2, "test.txt");
System.out.println(" 파일 명 : " + file3.getName());
System.out.println("디렉토리인지 검사 ");
System.out.println(" 디렉토리 일까 ? " + file3.isDirectory());
System.out.println(" 파일 일까 ? " + file3.isFile());
System.out.println();
3. new File(String parent. String Child)
==> 'parent' 디렉터리 안에 있는 'child'파일을 나타낸다.
File file4 = new File("d:/D_other", "test.txt");
System.out.println(" 파일 명 : " + file4.getName());
System.out.println("디렉토리인지 검사 ");
System.out.println(" 디렉토리 일까 ? " + file4.isDirectory());
System.out.println(" 파일 일까 ? " + file4.isFile());
System.out.println();
'프로그래밍 공부 > JAVA' 카테고리의 다른 글
JAVA - File Test(파일크기, 경로 ) (0) | 2020.11.02 |
---|---|
JAVA-FILE 디렉토리(폴더) 만들기 (0) | 2020.11.02 |
사용자 정의 데이터타입 (0) | 2020.10.12 |
JAVA - 객체와 클래스 (0) | 2020.10.12 |
JAVA - 객체지향 프로그래밍 (OOP) (0) | 2020.10.12 |