// //Readクラスを継承しています //ファイルを読み込むためのRead // // // package Rea; import java.io.*; public class FileRead extends Read { private String filename; private BufferedReader breader; private FileInputStream fistream; private InputStreamReader isreader; public FileRead(String name) { filename = name; breader = null; } public FileRead() { filename ="hello.txt"; breader = null; } public void init() { try { fistream = new FileInputStream(filename); isreader = new InputStreamReader(fistream); breader = new BufferedReader(isreader); }catch (Exception e){ e.printStackTrace(); } } public String read(int num) { char cbuf[] = new char[num]; try { if(-1 == breader.read(cbuf,0,num)) { return null; } }catch(Exception e) { return null; } return new String(cbuf); } public String readLine() { try{ return breader.readLine(); } catch(Exception e){ return null; } } public void fin() { try{ fistream.close(); fistream = null; isreader.close(); isreader = null; breader.close(); breader = null; }catch(Exception e) { ; } } public static void main(String []argsv) { Read fr = new FileRead(); fr.init(); System.out.println(fr.readLine()); fr.fin(); } }