テキストファイルの処理


  外部クラスのインスタンスメソッド



このメソッドの性質上、インスタンスメソッドにする理由はありませんが、( オブジェクト毎に保有すべきデータが無い )
メソッドから static を外す事によって呼び出し側はインスタンスを作成する必要が出て来ます

  
public class CLCOMP {

	public static void main(String[] args) {

		String filePath = "D:\\TEMP\\query.txt";
		String line = null;
		BufferedReader inFile = null;

		myFile myObj = new myFile();

		inFile = myObj.myOpen( filePath );
		if ( inFile == null ) {
			System.out.println( filePath + " を open できません" );
			return;
		}

		try {
			while ( ( line = inFile.readLine() ) != null) {
				System.out.println( line );
			}

			inFile.close();

		}
		catch ( Exception e ) {
			System.out.println( e.getMessage() );
		}

	}

}

class myFile {
	public BufferedReader myOpen( String filePath ) {

		BufferedReader inFile = null;

		try {
			inFile = new BufferedReader( new FileReader( filePath ) );
		}
		catch ( Exception e ) {
			return null;
		}

		return inFile;
	}
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ