public static void main(String[] args) {
RandomAccessFile file = null;
try {
file = new RandomAccessFile("tom.dat", "rw");
for (int i = 1; i < 11; i++)
file.writeInt(i);
long p = file.getFilePointer();
for (int i= 1; i < 11; i++){
file.seek(p - i * 4);
System.out.println(file.readInt());
}
} catch (Exception e) {
// TODO: handle exception
} finally {
try {
if (file != null) {
file.close();
}
} catch (IOException IgnoreWhenClose) {
}
}
}
RandomAccessFile file = null;
try {
file = new RandomAccessFile("tom.dat", "rw");
for (int i = 1; i < 11; i++)
file.writeInt(i);
long p = file.getFilePointer();
for (int i= 1; i < 11; i++){
file.seek(p - i * 4);
System.out.println(file.readInt());
}
} catch (Exception e) {
// TODO: handle exception
} finally {
try {
if (file != null) {
file.close();
}
} catch (IOException IgnoreWhenClose) {
}
}
}
解决方案 »
- 【Spring】Spring到底能给我带来什么好处?
- map的clear问题
- java写的树形用户权限管理源代码
- hibernate一对多关联
- 今天面试了一道题 请教!
- 什么方法能使网页的附件随网页的打开自动下载下来并运行
- 给点提示就送分!!
- 关于jndi的认识,初步学习,请大家帮忙看看
- Vector vSubInsureType=(Vector)hBaseInfo.get("vSubInsureType");(很简单的)
- (弱智问题,顺便散分)类变量占用的内存在什么时候释放?JFrame等在关闭后一定要调用dispose方法吗?如果不调用可以吗?
- 按字典顺序比较两个字符串”你”和”我”的大小关系(java实现)
- 请问在JSP中怎样传两个参数
00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0a
至于题意,就看你怎么理解了
String[] sstr = new String[intstr.length];
for(int i=0; i<intstr.length; i++){
sstr[i] = String.valueOf(intstr[i]);
}
这样就可以获得一个{1,2,3,4,5,6,7}的String类型数组了,然后你向文件里输出就行。应该是楼主要的东西了吧
public static void main(String args[]){
try{
RandomAccessFile raf = new RandomAccessFile("D:/JavaTest/tom.dat","rw");
for(int i=1;i<=10;i++){
raf.writeInt(i);
}
int fileIndex=(int) (raf.length()-4);
for(int i=1;i<=10;i++){
raf.seek(fileIndex);
System.out.println(raf.readInt());
fileIndex-=4;
}
}catch(IOException e){
e.printStackTrace();
}
}
}