/**
* 2007.09.06作成
* author@
*/
String[][] raw = new String[100][100];
/**
* タブを”\”に変換する
*/
// 文字ストリームの作成
FileReader in = new FileReader(new
File(InFile));
FileWriter out = new FileWriter(new
File(OutFile1));
// 読み込みと書き込み
int c;
while ((c = in.read()) != -1) {
// System.out.println(c);
if (c == 9) { // ”9”はタブを表す
c = 33; // ”33”は”!”を表す
out.write(c);
} else {
out.write(c);
}
}
in.close();
out.close();
String[]
strAry;
i = 0;
sc = new Scanner(new File(OutFile1)); //
ファイルを開く
pw = new PrintWriter(OutFile2); //
ファイルを開く
while (sc.hasNextLine()) {
raw[i][0] = sc.nextLine();
raw[i][0] = ('!' + raw[i][0] +
'!'); // 行の最初と最後に”!”を追加
strAry =
raw[i][0].split("!", -1); // ”-1”
は空白文字も読み込むことを表す
for (int n = 0; n < strAry.length;
n++) {
pw.print("[" + n + "]" +
strAry[n]);
raw[i][n] = strAry[n];
}
pw.println("");
// 改行
i++;
}
imax = i;
sc.close();
pw.close();
/*****************************************/
このプログラムで,タブ区切りのファイルを読み込むことが出来ます。
読み込まれたファイルは,raw[][]に格納されます。
raw[i][0]は予備用のスペースとして空白文字を入れてあります。
区切り文字には”!”を使用しました。