Javaでテキストファイルから特定の文字列を検索して抽出する

Javaコード:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class FindStrInTxt {

String encoding = “UTF-8";
public static void main(String[] args) throws IOException {
findStringInFile(“C://start.txt");
}

public static void findStringInFile(String path) throws IOException{
File file = new File(path);
InputStreamReader read = new InputStreamReader(new FileInputStream(file),"UTF-8″);
BufferedReader bufferedReader = new BufferedReader(read);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if(line.startsWith(“#")){
continue;
}
if (line.contains(“startnews24")) {
System.out.println(line);
}
}
}
}

Java

Posted by arkgame