1.批处理文件(bat)
简单的说,批处理的作用就是自动的连续执行多条命令 .编写bat处理文件可以使用记事本的方式:
常见批处理文件的命令:
echo 表示显示此命令后的字符
tiltle 设置窗口的标题。
echo off 表示在此语句后所有运行的命令都不显示命令行本身
color 设置窗体的字体颜色。
@与echo off相象,但它是加在每个命令行的最前面,表示运行时不显示这一行的命令行(只能影响当前行)。
pause 运行此句会暂停批处理的执行并在屏幕上显示Press any key to continue...的提示,等待用户按任意键后继续
rem 表示此命令后的字符为解释行(注释),不执行,只是给自己今后参考用的(相当于程序中的注释) 或者%注释的内容%
%[1-9]表示参数,参数是指在运行批处理文件时在文件名后加的以空格(或者Tab)分隔的字符串
例子:
2.对象拷贝
一:浅拷贝:拷的都是栈中值
拷贝对象需要实现Cloneable接口(其实这个接口没有方法只是起到标识的作用)
起到效果:只是拷贝了成员,对于成员中的引用其他对象,拷贝只是栈中值而不是堆中值
二:深拷贝:拷的都是堆中值就是实际的值
原理:对象的深克隆就是利用对象的输入输出流将对象存到硬盘文件中再从文件中读取对象
注意:所以让需要克隆的对象实现Serilization接口来完成对象存取操作ObjectInputStream,ObjectOutputStream
起到作用:拷贝所有,引用对象的值也拷贝了
三:例子
/** * 对象深拷贝浅拷贝 * @author Administrator * */ public class Copy { private static ObjectInputStream objectInputStream; public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException { //浅克隆 Person p1=new Person("1", "小王", new Address("安徽")); Person p2=p1.clone(); p1.id="2"; p1.address.city="北京"; System.out.println(p1.toString());//城市:都变为改变后的值北京 System.out.println(p2.toString());//城市:都变为改变后的值北京 //------浅拷贝引用成员拷贝的是栈中值----------// //深克隆 Address address = new Address("广州"); Person p3 = new Person("1","狗娃",address); writeObj(p3); Person p4 =readObj(); p4.address.city = "长沙"; System.out.println("p1:"+ p3); System.out.println("p2:"+ p4); } //文件写到硬盘中 //再从文件中读取对象的信息 public static Person readObj() throws ClassNotFoundException, IOException{ FileInputStream fileInputStream = new FileInputStream("F:\\obj.txt"); objectInputStream = new ObjectInputStream(fileInputStream); return (Person) objectInputStream.readObject(); } //先要把对象写到文件上。 public static void writeObj(Person p) throws IOException{ //建立一个文件 的输出流对象 FileOutputStream fileOutputStream = new FileOutputStream("F:\\obj.txt"); //建立对象的输出流 ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); //把对象写出 objectOutputStream.writeObject(p); //关闭资源 objectOutputStream.close(); } } /** * 这个对象会被浅拷贝和深拷贝 * 浅拷贝:Cloneable只是起到一个标识的作用然后重写对象的克隆方法通过他调用父类构造方法 * @author Administrator * */ class Person implements Cloneable,Serializable{ private static final long serialVersionUID = 1L; String id; String name; Address address; public Person(String id,String name,Address address){ this.id=id; this.name=name; this.address=address; System.out.println("=======构造方法调用了==="); } @Override public String toString() { return "编号:"+ this.id+" 姓名:"+ this.name+" 地址:"+ address.city; } @Override public Person clone() throws CloneNotSupportedException{ return (Person)super.clone(); } } /** * Person类成员类对象 * 为了深拷贝需要为其加上Serializable * @author Administrator * */ class Address implements Serializable{ private static final long serialVersionUID = 1L; String city; public Address(String city){ this.city = city; } }