icon 情報整理

Javaでファイル読み込み(20220503)

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class file_read{
public static void main(String[] args){
try{
FileInputStream fs = new FileInputStream("data.txt");
InputStreamReader isr = new InputStreamReader(fs, "UTF-8");
BufferedReader br = new BufferedReader(isr);

String data;
while((data = br.readLine()) != null){
System.out.println(data);
}
br.close();
}catch(IOException e){
e.printStackTrace();
}
}
}