Yeon's Frame
  • Intro
  • Project
    • 미소웨더
      • 기획 - 아이디어 및 유스케이스 정리
      • DB 설계 - JPA 활용 중심
  • Study
    • Spring
      • Spring Feature
      • N+1
      • OSIV
      • @Valid
      • Spring Boot Feature
      • Spring 5 Feature
      • JPA vs MyBatis
      • Filter, Interceptor
      • Persistence Context
      • @Transactional
      • @Controlleradvice, @ExceptionHandler
      • Spring Security
      • Dispatcher Servlet
      • @EnableWebMvc
      • Stereo Type
      • AOP
      • JPA Repository
    • Infrastructure
      • Git
      • DNS
      • JWT
      • DevOps
      • Docker
      • Jenkins
      • Cloud Computing
      • MSA
    • Clean Code
      • 깨끗한 코드
      • 의미있는 이름
      • 함수
      • 주석
      • 형식 맞추기
      • 객체와 자료구조
      • 오류 처리
      • 경계
      • 단위테스트
      • 클래스
      • 시스템
  • Basic
    • Java
      • OOP
      • OOL Features
      • Class & Objects
      • Instance & Heap Memory
      • Constructor
      • Reference Type Uses
      • Access Modifier & Hiding
      • This
      • Collaboration
      • Static
      • Inheritance
      • Polimorphism & Casting
      • Abstract Class
      • Interface
      • Object Class
    • Java Coding
      • JVM
      • String, StringBuffer, StringBuilder
      • SOF
      • Blockcing/NonBlocking
      • Enum
      • Static
      • Thread
      • hashCode() | equals()
      • JDK8
      • Stream
      • Optional
      • Lambda & Closure
      • Exception
      • Garbage Collecter
      • Collection
      • Call by Value & Call by Reference
      • Generic
    • Java_Advance
      • Inner Class
      • Lambda Expression
      • Functional Interface
      • OOP vs Lambda Expression
      • Stream
      • Reduce()
      • Exception Handling
      • Custom Exception
      • Error Log
      • IO Stream
      • IO Stream - Serialization
      • File Class
      • Decorator Pattern
      • Thread
    • Data Structure
      • Intro
      • Generic(1)
      • Generic(2) T extends
      • Generic(3) Method
      • Collection Frameworks
      • List
      • Iterator
      • Set
      • Comparable & Comparator
      • Map
  • Practice
    • Algorithm
      • Strategy
        • Primitive, Reference, Generic
        • Number Data Types
        • For-Each
        • Array, Queue, ArrayDeque
        • Array vs ArrayList
Powered by GitBook
On this page
  1. Basic
  2. Java_Advance

File Class

  • 파일 개념을 추상화한 클래스

  • 입출력 기능은 없고, 파일의 이름, 경로, 읽기 전용등의 속성을 알수 있음

  • 이를 지원하는 여러 메서드들이 제공됨

public class FileTest {

	public static void main(String[] args) throws IOException {

		File file = new File("D:\\JAVA_LAB\\Chapter6\\newFile.txt");
		file.createNewFile();
		
		System.out.println(file.isFile());
		System.out.println(file.isDirectory());
		System.out.println(file.getName());
		System.out.println(file.getAbsolutePath());
		System.out.println(file.getPath());
		System.out.println(file.canRead());
		System.out.println(file.canWrite());
		
		file.delete();
	}
}

RandomAccessFile 클래스

  • 입출력 클래스 중 유일하게 파일에 대한 입력과 출력을 동시에 할 수 있는 클래스

  • 파일 포인터가 있어서 읽고 쓰는 위치의 이동이 가능함

  • 다양한 메서드가 제공됨

public class RandomAccessFileTest {

	public static void main(String[] args) throws IOException {
		RandomAccessFile rf = new RandomAccessFile("random.txt", "rw");
		rf.writeInt(100);
		System.out.println("파일 포인터 위치:" + rf.getFilePointer());
		rf.writeDouble(3.14);
		System.out.println("파일 포인터 위치:" + rf.getFilePointer());
		rf.writeUTF("안녕하세요");
		System.out.println("파일 포인터 위치:" + rf.getFilePointer());
	
		rf.seek(0);
		System.out.println("파일 포인터 위치:" + rf.getFilePointer());
		
		int i = rf.readInt();
		double d = rf.readDouble();
		String str = rf.readUTF();
	
		System.out.println("파일 포인터 위치:" + rf.getFilePointer());
		System.out.println(i);
		System.out.println(d);
		System.out.println(str);
	}
}
PreviousIO Stream - SerializationNextDecorator Pattern

Last updated 2 years ago