序列化出错 求指点

问题描述

importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.ObjectInputStream;importjava.io.ObjectOutputStream;importjava.io.Serializable;importjava.util.ArrayList;importjava.util.Scanner;publicclassTest{publicstaticvoidmain(String[]args)throwsException{Manager.start();}}classManager{privatefinalstaticManagerm=newManager();privateManager(){}publicManagergetMan(){returnm;}privatestaticArrayList<Person>list;//启动首页publicstaticvoidstart()throwsException{for(inti=1;i<51;i++){System.out.print("=");}System.out.println();System.out.println("[1]查询所有联系人");System.out.println("[2]增加联系人信息");System.out.println("[3]删除联系人信息");System.out.println("[4]修改联系人信息");for(inti=1;i<51;i++){System.out.print("=");}System.out.println();while(true){System.out.println("请选择:");Scannersc=newScanner(System.in);intsel=sc.nextInt();switch(sel){case1:look();break;case2:addCon();break;case3:del();break;case4:res();break;default:continue;}}}staticObjectOutputStreamoos;staticObjectInputStreamois;//增加联系人信息privatestaticvoidaddCon()throwsException{list.clear();Scannersc=newScanner(System.in);Personp=newPerson();Filefile=newFile("Contacts.txt");oos=newObjectOutputStream(newFileOutputStream(file));ois=newObjectInputStream(newFileInputStream(file));if(file.length()!=0){list=(ArrayList<Person>)ois.readObject();for(Personp1:list){System.out.println(p1);}}//联系人信息:编号、姓名、年龄、QQ、电话、邮箱while(true){System.out.println("请输入编号:");p.setId(sc.next());System.out.println("请输入姓名:");//。。。。。。。。。。。。。。。。。p.setName(sc.next());while(true){System.out.println("请输入年龄:");p.setAge(sc.nextInt());if(p.getAge()>0&&p.getAge()<130){break;}else{System.out.println("输入有误,请重新输入年龄!");continue;}}System.out.println("请输入QQ:");p.setQq(sc.nextLong());System.out.println("请输入联系号码:");p.setTel(sc.next());while(true){System.out.println("请输入邮箱:");p.setEmail(sc.next());if(p.getEmail().matches("\w+@\w+\.\w+")){break;}else{System.out.println("邮箱输入有误,请重新输入!");continue;}}System.out.println(p);while(true){System.out.println("是否保存该联系人信息:【1】是【2】否");intsele=sc.nextInt();if(sele==1){list.add(p);break;}elseif(sele==2){System.out.print("取消保存");sleep();}else{System.out.println("输入有误!");continue;}}System.out.println("是否继续添加联系人?");System.out.println("【1】是【2】否");intcon=sc.nextInt();if(con==1){continue;}else{oos.writeObject(list);System.out.println("退出至首页");sleep();oos.close();ois.close();start();}}}//查询privatestaticvoidlook(){}//删除privatestaticvoiddel(){}//修改privatestaticvoidres(){}//sleepprivatestaticvoidsleep(){for(inti=1;i<7;i++){System.out.print(".");try{Thread.sleep(100);}catch(InterruptedExceptione){//TODOAuto-generatedcatchblockthrownewRuntimeException(e);}}System.out.println();}}classPersonimplementsSerializable{privateStringid;privateStringname;privateintage;privatelongqq;privateStringtel;privateStringemail;Person(){}publicPerson(Stringid,Stringname,intage,longqq,Stringtel,Stringemail){super();this.id=id;this.name=name;this.age=age;this.qq=qq;this.tel=tel;this.email=email;}publicStringgetId(){returnid;}publicvoidsetId(Stringid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicintgetAge(){returnage;}publicvoidsetAge(intage){this.age=age;}publiclonggetQq(){returnqq;}publicvoidsetQq(longqq){this.qq=qq;}publicStringgetTel(){returntel;}publicvoidsetTel(Stringtel){this.tel=tel;}publicStringgetEmail(){returnemail;}publicvoidsetEmail(Stringemail){this.email=email;}@OverridepublicStringtoString(){return"Person[id="+id+",name="+name+",age="+age+",qq="+qq+",tel="+tel+",email="+email+"]";}}

时间: 2024-10-18 07:55:57

序列化出错 求指点的相关文章

wsdl-xfire 客户端调用出错,求高人指点

问题描述 xfire 客户端调用出错,求高人指点 根据wsdl用myeclipse 生成的客户端,这个类为什么报错,后面的这些代码什么意思,求高人指点 props.put("annotations.allow.interface", true); AnnotationServiceFactory asf = new AnnotationServiceFactory( new Jsr181WebAnnotations(), tm, new AegisBindingProvider( ne

scanf_s while循环-VS2015,用scanf_s警告,循环输入的第一次正常,第二次出错。求指点

问题描述 VS2015,用scanf_s警告,循环输入的第一次正常,第二次出错.求指点 刚接触VS2015,在.net3.5 x86下写了个c程序. #include int main(void) { const int WEEK = 7; int days, weeks,left; printf("Please enter the numbers of days.n"); printf("Enter 0 to quit.n"); scanf_s("%d&

c++编译出错,求指点怎么更改?

问题描述 c++编译出错,求指点怎么更改? #include using namespace std; void trim(const char exp[],int& lo,int& hi) { while ((lo<=hi)&&(exp[lo]!='(')&&(exp[lo]!=')'))lo++; while ((lo<=hi)&&(exp[hi]!='(')&&(exp[hi]!=')'))hi--; } i

关于 string iterators imcompatiable问题 能编译 运行出错 求大大指点

问题描述 关于 string iterators imcompatiable问题 能编译 运行出错 求大大指点 #include #include #include #include #include using namespace std; struct com{ bool operator()(const string &s1, const string &s2){ int c1 = count(s1.begin(), s2.end(), '1'); int c2 = count(s2

xcode编译opencv出错,求指点

问题描述 xcode编译opencv出错,求指点 OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /Users/wangxiaoxiao/Downloads/opencv-3.0.0/modules/highgui/src/window.cpp, line 271 libc++abi.dylib: terminating with uncaught exception

web xml-Web 项目中web.xml的配置有什么原则么有,怎么老是出错。求指点

问题描述 Web 项目中web.xml的配置有什么原则么有,怎么老是出错.求指点 严重: Parse error in application web.xml file at jndi:/localhost/TestStruts/WEB-INF/web.xml com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence. at

cvset*d-在实现鼠标绘图时,使用cvSet2D来画轨迹,为什么在边缘处出界。求指点。

问题描述 在实现鼠标绘图时,使用cvSet2D来画轨迹,为什么在边缘处出界.求指点. 下面是代码, /* 创建白色图像,通过鼠标左键绘图,右键实现橡皮擦功能 */ #include <iostream> #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp> using namespace std; using namespace cv; bool LFlag = false; bool

java-好多看不懂...求指点...

问题描述 好多看不懂...求指点... 程序应该没什么问题,可就是编译的时候就出现问题了,问题:内些错误到底怎么看呢?其实我还有很多看不懂...但还是请前辈们先帮我解决这两个问题吧...谢谢大家了啊!package mouse; import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import java.util.*;import javax.swing.*; public class MouseFrameText {

安卓,colordrawable不显示,求指点

问题描述 安卓,colordrawable不显示,求指点 代码 <ImageView android:id="@+id/imageview" android:layout_width="100dp" android:layout_height="100dp" /> imageView=(ImageView)super.findViewById(R.id.imageview); imageView.setBackground(0xff6