日期:2014-05-20  浏览次数:20844 次

Java如何获得文件在硬盘上存储的物理地址,如何获得数据在内存中的物理地址?
Java如何获得文件在硬盘上存储的物理地址,如何获得数据在内存中的物理地址?

------解决方案--------------------
Java如何获得文件在硬盘上存储的物理地址:
不行,JAVA未提供该方法API,其实就算用其它语言也很难的吧;毕竟其它语言直接打交道的也不是硬件,而是操作系统;如果操作系统未提供该API的话,所有的语言都做不到;
如何获得数据在内存中的物理地址? 
数据在内存中是以对象存在的,一个不太通用的办法是用System.out.println(对象);
这样子会打出对象类名+@+对象地址;
因为这是一般的对象的toString()的实现方式;
------解决方案--------------------
楼上这样说是错误的,API这样写
引用
public String toString()
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())


默认打印出的为该类名+@+该对象的哈西码的十六进制形式
可以做实验看看啊,我复写hashCode方法
public class StringRepresent {
public static void main(String[] args) {
 StringRepresent s=new StringRepresent();
System.out.println(s);

}

@Override
public int hashCode() {
return 0;

}
}

打印出来为
StringRepresent@0