Java??????????
???????????? ???????[ 2013/11/12 11:18:14 ] ????????
????3?????ж?????????
/**
* ???????λ????????????????????е????????
*/
public static void readFileByLines(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("???????λ?????????????ζ?????У?");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// ??ζ?????У????????null????????
while ((tempString = reader.readLine()) != null) {
// ????к?
System.out.println("line " + line + ": " + tempString);
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
????4???????????????
/**
* ?????????????
*/
public static void readFileByRandomAccess(String fileName) {
RandomAccessFile randomFile = null;
try {
System.out.println("?????????????????");
// ???????????????????????????
randomFile = new RandomAccessFile(fileName?? "r");
// ?????????????
long fileLength = randomFile.length();
// ??????????λ??
int beginIndex = (fileLength > 4) ? 4 : 0;
// ???????????λ?????beginIndexλ?á?
randomFile.seek(beginIndex);
byte[] bytes = new byte[10];
int byteread = 0;
// ??ζ?10???????????????????10???????????μ?????
// ????ζ?????????????byteread
while ((byteread = randomFile.read(bytes)) != -1) {
System.out.write(bytes?? 0?? byteread);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (randomFile != null) {
try {
randomFile.close();
} catch (IOException e1) {
}
}
}
}
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11