テキストファイルの処理


  外部クラスの static メソッド



クラスを外部にしてメソッドを static にし、いわゆる クラスメソッド として実行します

  
public class CLCOMP {

	public static void main(String[] args) {

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

		inFile = myFile.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 {
	static 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ライブラリ