テキストファイルの処理


  テキストファイル読み込みクラス



BufferedReader の1 行のテキスト読み込み部分をラップして、c ライクにしたものです。
読み込みデータを呼び出し側で用意して、そこにデータセットさせる為に String の配列を使用しています。

  
public class CLCOMP {

	public static void main(String[] args) {

		String filePath = "D:\\TEMP\\query.txt";
		String line [] = {""};

		myFile myObj = new myFile();

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

		while ( myObj.get( line ) ) {
			System.out.println( line[0] );
		}

		myObj.close();

	}

}

class myFile {

	private BufferedReader inFile = null;

	public boolean open( String filePath ) {

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

		return true;
	}
	public boolean get( String buff [] ) {

		String line;

		try {
			line = inFile.readLine(); 
			if ( line == null ) {
				return false;
			}
			buff[0] = line;
		}
		catch ( Exception e ) {
			return false;
		}

		return true;
	}
	public void close( ) {

		try {
			inFile.close();
		}
		catch ( Exception e ) {
		}

		return;
	}
}
  










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ