packagecn.com.test05;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;importjava.io.OutputStream;classPerson{
String name;intage;
String image;byte[] imageB;
String url;publicString getName() {returnname;
}public voidsetName(String name) {
System.out.println(Thread.currentThread().getName());this.name =name;
}public intgetAge() {returnage;
}public void setAge(intage) {this.age =age;
}publicString getImage() {returnimage;
}public voidsetImage(String image) {this.image =image;
}public byte[] getImageB() {returnimageB;
}public void setImageB(byte[] imageB) {this.imageB =imageB;
}publicString getUrl() {returnurl;
}public voidsetUrl(String url) {this.url =url;
}publicString toString(){return "我叫"+name+"=="+age+"===="+image;
}
}public classt03 {public static void main(String[] args) throwsException {
Person p= newPerson();
t03.get(p);
System.out.println(p);
out(p);
}public static void out(Person p) throwsException{
File f= new File(p.url+"a.txt");
OutputStream out= newFileOutputStream(f);
out.write(p.toString().getBytes());
outImage(p.getUrl(),p.getImage(),p.getImageB());
out.close();
}public static void outImage(String url,String image,byte[] b) throwsException{
File f= new File(url+image);
OutputStream out= newFileOutputStream(f);
out.write(b);
out.close();
}public static void get(Person p) throwsException{
File f= new File("F:\\a.txt");
InputStream in= newFileInputStream(f);byte[] b=new byte[(int) f.length()];
in.read(b);
String str= newString(b);
System.out.println(str);
String[] s= str.split("\r\n");
p.setName(getValue(s[0]));
p.setAge(Integer.parseInt(getValue(s[1])));
p.setImage(getValue(s[2]));
p.setUrl(getValue(s[3]));
p.setImageB(getImageB(getValue(s[2])));
in.close();
}public static byte[] getImageB(String str) throwsException{
File f= new File("F:\\"+str);
InputStream in= newFileInputStream(f);byte[] b=new byte[(int) f.length()];
in.read(b);
in.close();returnb;
}public staticString getValue(String str){return str.split("=")[1];
}
}