comment lire les numéros d'un fichier ??? Quand j'utilise la méthode readInt, j'obtiens un grand nombre, et il n'est pas égal au nombre d'un fichier.RandomAccessFile readInt
comment y remédier ??
Scanner est pas une bonne idée, becouse fichier contient plus de 1000 numéros de millions ... il prend très longtemps ...
oui, fichier texte.
Le fichier contient des symboles spatiaux divisés. par exemple (test.txt)
1 2 4 -4004 15458 8876
public static void readByMemoryMappedFile(int buffer[], String filename) throws IOException
{
int count = 0;
RandomAccessFile raf = new RandomAccessFile(filename, "r");
try {
MappedByteBuffer mapFile = raf.getChannel().map(MapMode.READ_ONLY, 0, raf.length());
StringBuilder b = new StringBuilder();
try {
while (mapFile.hasRemaining()) {
byte read = mapFile.get();
if (read == ' ' && b.length() > 0) {
buffer[count++] = mapFile.getInt();//Integer.parseInt(b.toString());
b.delete(0, b.length());
} else {
b.append((char) read);
}
}
} catch (BufferUnderflowException e) {
// Всё, файл закончился
}
if (b.length() > 0) {
buffer[count++] = Integer.parseInt(b.toString());
}
} finally {
raf.close();
}
}
ainsi, i attaché rapport:
// operation: time
reading: 39719 // t0
reading: 28297 // t1
reading: 56719 // t2
reading: 125735 // t3
reading: 199000 // t4
t0 < t1 t2 < < t3 t4 <
Comment changer le comportement de mon programme qui obtient ceci: t0 ~ t1 ~ t2 ~ t3 ~ t4 ???
comment ils sont stockés? –
la question clé, est les données dans un format binaire ou texte? Ce n'est pas clair dans votre question. –