1行で構成されるファイルがあります:
1 , 1 2 , 1 3 6 , 4 ,...
この表現では、スペースが整数とコンマを区切ります。この文字列は非常に大きいため、RandomAccessFile.readLine() で読み取ることができません (ほぼ 4 Gb が必要です)。そのため、10 個の整数を格納できるバッファーを作成しました。私の仕事は、文字列内のすべての整数をソートすることです。
助けてくれませんか?
編集
@オスカー・レイエス
いくつかの整数シーケンスをファイルに書き込み、それから読み取る必要があります。実際、私はそれを行う方法を知りません。私は初心者です。そこで、文字を使用して整数を書き込むことにしました。整数間の区切り文字は「,」であり、シーケンス間の区切り文字は「\n\r」です。だから私はそれを読むモンスターを作成しました:
public BinaryRow getFilledBuffer(String filePath, long offset) throws IOException{
mainFile = new RandomAccessFile(filePath, "r");
if (mainFile.length() == 0){
return new BinaryRow();
}
StringBuilder str = new StringBuilder();
mainFile.seek(mainFile.length()-4); //that is "\n" symbol
char chN = mainFile.readChar();
mainFile.seek(offset);
int i = 0;
char nextChar = mainFile.readChar();
while (i < 11 && nextChar != chN){
str.append(nextChar);
if (nextChar == ','){
i++;
if (i == 10){
break;
}
}
nextChar = mainFile.readChar();
}
if (nextChar == chN){
position = -1;
}else{
position = mainFile.getFilePointer();
}
BinaryRow br = new BinaryRow();
StringBuilder temp = new StringBuilder();
for (int j = 0; j < str.length(); j++){
if ((str.charAt(j) != ',')){
temp.append(str.charAt(j));
if (j == str.length() - 1){
br.add(Integer.parseInt(temp.toString()));
}
}else{
br.add(Integer.parseInt(temp.toString()));
temp.delete(0, temp.length());
}
}
mainFile.close();
return br;
}
あなたがそれを行う方法をアドバイスできるなら、それをしてください=)