1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
private int getFINIndex2() {
try {
ra = new RandomAccessFile(pathname,"r");
ds = new DataInputStream(new BufferedInputStream(new FileInputStream(pathname)));
byte[] buff = new byte[1000];
String strBuff;
int toReturn = 0;
int index = -1;
boolean eof = false;
try{
ra.seek(0);
int nbLines = 0;
while(!eof){
ra.read(buff);
strBuff = new String(buff);
if (strBuff.indexOf("\u001A") != -1){ // 26 = caractère de fin de la partie en-tête...
//cest la bonne ligne
toReturn += strBuff.indexOf("\u001A");
System.out.println("toReturn = "+toReturn);
return toReturn;
}
else {
toReturn += strBuff.length();
}
}
return -1;
}
catch (EOFException e) {
eof = true;
}
catch(Exception e){
e.printStackTrace();
}
}
catch(NumberFormatException nbe){
nbe.printStackTrace();
System.out.println("NOT A NUMBER");
}
catch(NullPointerException ne){
ne.printStackTrace();
System.out.println("ERROR IN ATTRIBUTE NAME : NOT FOUND IN FILE");
}
catch(Exception e){
e.printStackTrace();
}
return -1;
} |