[TIL] 25-11-03

suni_develop·2025년 11월 5일

TIL

목록 보기
1/1

과제 제출하는 법

  1. local 리포지토리에서 우선 gradle 방식으로 코딩
  2. 강사님의 제출용 리포지토리 fork 후 local에 clone
  3. 필요한 파일만 복사하여 적용한 후 git add .
  4. git checkout -b BE10-wonsuyeon
  5. git commit -m “커밋 메시지”
  6. git push origin BE10-wonsuyeon

String에서 특정 문자열 검색

String string = "abc";
string.equals("abc");
string.startsWith("ab");

파일 입출력하기

입력

String fileName = "src/main/test.txt";

try (FileWriter writer = new FileWriter(fileName)) {
	writer.write(makeJson(quote));
}

FileWriter의 경우 인수로 전달된 이름의 파일이 없으면 생성하고, 있으면 해당 파일에 접근. But 상위 폴더가 있어야함. 없을경우 에러

출력

File file = new File(fileName);

if (file.exists()) {
	try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
		String line = reader.readLine(); //한줄읽기
	}
}

File은 상위폴더가 없더라도 동작. 객체는 생성됨

파일을 한줄씩 모두 읽는경우 while(line = reader.readLine() != null) 사용

profile
렛츠고

0개의 댓글