[JAVA] 深克隆 另外实现方法【序列化】
private static List cloneObject(
Object obj) throws Exception {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(obj);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut
.toByteArray());
ObjectInputStream in = new ObjectInputStream(byteIn);
return in.readObject();
}
相关文档:
Java配置文件读取有各种不同的文件,但是由于打包Jar后的路径改变,往往在项目中能正确读取的配置文件在Jar后变成文件不存在的杯具,下在提出几各不同的配置文件读取方式,仅供参考
一、直接文件读取
File f = new File("you config file path");
FileReader fr = new FileReader(f);
BufferReader br = new ......
前言
在Java语言中,equals()和hashCode()两个函数的使用是紧密配合的,你要是自己设计其中一个,就要设计另外一个。在多数情况 下,这两个函数是不用考虑的,直接使用它们的默认设计就可以了。但是在一些情况下,这两个函数最好是自己设计,才能确保整个程序的正常运行。最常见的是当 一个对象被加入集合对象(collectio ......
参考代码:
class SuperClass {
private int n;
SuperClass() {
System.out.println("SuperClass()");
}
SuperClass(int n) {
System.out.println("SuperClass(" + n + ")");
this.n = n;
}
}
class SubClass extends SuperClass {
private int n ......
在java代码中经常有读取外部资源的要求:如配置文件等等,通常会把配置文件放在classpath下或者在web项目中放在web-inf下.
1.从当前的工作目录中读取:
try {
BufferedReader in = new BufferedReader(new InputStreamRea ......
好久没用java,突一写起来,发现机器上没有设置环境变量,把设置方法总结一下
1. 修改/etc/profile文件
如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题。
·用文本编辑器打开/etc/profile
·在pr ......