이전 2016 >/JAVA
2. 저장된 파일에서 필요한 값 찾기. readLine
망이방
2014. 7. 23. 15:37
/* m3u8 파일 리딩 : URL */
import java.io.*;
public class TextFileReading
{
public static void main(String[] args){
StringBuffer sb = new StringBuffer();
FileReader readFile;
BufferedReader br;
String getLine;
try {
readFile = new FileReader("C:/1/1.txt"); // 파일경로
br = new BufferedReader(readFile);
String resultUrl = "";
while((getLine = br.readLine()) != null){ // 한줄씩 읽기 (마지막줄 체크)
System.out.println(getLine);
if(getLine.startsWith("http")){ // 파일중 http 로 시작하는 줄 찾아서 저장.
resultUrl = getLine;
}
}
System.out.println("URL :"+ resultUrl);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}