Tag Archives: raw

[Android] 텍스트 파일(컴파일되지 않은)을 읽어서 String 으로 변환하기

By | 12월 29, 2020

InputStream in = getResources().openRawResource(R.raw.oss_license); StringBuilder sb = new StringBuilder(); Scanner sc = new Scanner(in); while (sc.hasNextLine()) { sb.append(sc.nextLine()).append(“\n”); } sc.close(); String contents = sb.toString();   * /res/raw 디렉토리에 있는 파일은 컴파일되지 않는다고 해서 raw 디렉토리를 별도로 생성하여 oss_license.txt 파일을 그 안에 넣어 둠. * /res/raw 디렉토리 안에 있는 파일을 읽을 수 있는 openRawResource() 메서드를 Android… Read More »