java中用readObject()方法,用while遍历时报EOFException

package sequenceDamo;

import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SequenceDemo {

public static void main(String[] args) throws IOException, ClassNotFoundException {
    File s=new File("d:/Mydoc/123.txt");
    Students zhan=new Students("张三",21,true);
    Students li=new Students("李三",22,true);
    Students liu=new Students("刘三",20,true); 
    ObjectOutputStream dos=new ObjectOutputStream(new FileOutputStream(s));
    dos.writeObject(zhan);
    dos.writeObject(li);
    dos.writeObject(liu);
    System.out.println("序列化完成");
    dos.flush();
    dos.close();
    ObjectInputStream fos=new ObjectInputStream(new FileInputStream(s));
    Students m=null;
    try{
        while((m=(Students)fos.readObject())!=null){
        System.out.println("名字:"+m.getName()+
                "\t年龄:"+m.getAge()+"\t性别:"+
                (m.isGender()?"男":"女"));    
    }
    }catch(EOFException e){
        System.out.println("输出结束");
    }
    fos.close();
}

}
运行结果
图片说明

5个回答

readObject这方法没办法判断是否还有对象可读,所以要么你捕获异常自己处理,
要么自己弄一个结束对象比如null,来判断是否还有可读的对象

有网友提出在dos.writeObject(liu);后加个dos.writeObject(null);能解决
试试看看呢

编程是一种美德,是促使一个人不断向上发展的一种原动力。

对象流只能被读取一次,你多次调用肯定会出现这个异常

s,重新new一看看

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
【java】readObject的强制类型转换问题

我在用ObjectInputStream的 readObject方法时,将其强转为定义好的UserInfo类型,为什么会弹出强制类型转换用的是String,readObject的方法 返回的不是Object的对象吗? ![图片说明](https://img-ask.csdn.net/upload/201707/09/1499561086_157779.png) ![图片说明](https://img-ask.csdn.net/upload/201707/09/1499561095_32404.png)

java的ObjectInputStream的readObject

为何读出来的对象是null,代码: import java.io.*; import java.util.ArrayList; public class NewClass { public static void main(String[] args) throws ClassNotFoundException,IOException{ try(ObjectOutputStream output =new ObjectOutputStream(new FileOutputStream("didi.dat"));){ output.writeObject(new Student_2("林琅天","河南","17723526243","3220063463@qq.com",3)); } try(ObjectInputStream input =new ObjectInputStream(new FileInputStream("didi.dat"));){ Student_2 hh=(Student_2)(input.readObject()); System.out.println(hh.toString()); System.out.print(hh); } } } 结果是这样的:Student null null null null 3 Student null null null null 3成功构建 (总时间: 0 秒)

ObjuectInputStream对象使用readObject()方法时抛出异常

背景:项目原本是当用户登录客户端输入正确密码后,对方就可以打网络电话过来,已方就可以触发接电话界面。 现在项目改需求,要求第一次登录成功后,以后退出程序,后台仍然有服务存在,仍然发心跳包给服务器,保持在线状态,保证仍能监听第二方来电。 目前:我已经实现服务在后台仍然发心跳包给服务器,不随程序的退出而关闭,同时也是随开机自启动。 问题:我在服务里启动了一个循环读取服务器发来的命令,在服务里建立了一个ObjuectInputStream对象in,并用in.readObject()读取命令。当服务还在后台,程序还没启动时,对方来电会先触发【来电等待】界面,由于项目需要,我方需要插入一个外置设备,触发登录界面,再输入密码后才能再跳转回【来电等待】界面进行接听。在插入外置设备跳转到登录界面时,in会报错,抛出java.io.EOFException的错误。我在写的时候已经在最后写入了null值,在读取时也对获取的值进行判断是否为null,但仍在抛出异常。 不知道我有没表述清楚,求大神搭救

文件写入了userInfo的值,但readObject读取文件中的对象,值全都是Null

FileInputStream fileInputStream = null; ObjectInputStream objectInputStream = null; ArrayList<UserInfo> userList = null; try { fileInputStream = new FileInputStream(file); objectInputStream = new ObjectInputStream(fileInputStream); userList = new ArrayList<UserInfo>(); boolean flag = true; while(flag){ try { Object obj = objectInputStream.readObject(); //这里返回的对象的值全是null UserInfo userInfo = (UserInfo) obj; userList.add(userInfo); flag = true; } catch (Exception e) { flag = false; } if(!flag){ break; } } } catch (FileNotFoundException e) { System.out.println("未找到文件,请检查文件路径"); e.printStackTrace(); } finally { objectInputStream.close(); fileInputStream.close(); }

for循环遍历list集合报null异常或者报"#" Index: 10, Size: 10

报错语句 List<OrderModel> orderList = new ArrayList(); orderList = orderEbi.getAll(oqm,pageNum,pageCount); if (orderList!=null&&!orderList.isEmpty()&&orderList.get(i).getOrderTime().toString().substring(0, 10) == orderList.get(e).getOrderTime().toString().substring(0, 10)) 报错信息 2020-05-30 21:14:57,023 com.opensymphony.xwork2.util.logging.commons.CommonsLogger.error(CommonsLogger.java:42) "#" Index: 10, Size: 10 java.lang.IndexOutOfBoundsException: Index: 10, Size: 10 at java.util.ArrayList.rangeCheck(ArrayList.java:635) at java.util.ArrayList.get(ArrayList.java:411) at sd.admin.order.web.OrderAction.list2(OrderAction.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293) at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117) at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108) at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369) at ognl.ASTMethod.getValueBody(ASTMethod.java:90) at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) at ognl.SimpleNode.getValue(SimpleNode.java:258) at ognl.Ognl.getValue(Ognl.java:494) at ognl.Ognl.getValue(Ognl.java:458) at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309) at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340) at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250) at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at sd.util.interceptor.LoginInterceptor.intercept(LoginInterceptor.java:124) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at sd.util.interceptor.ErrorInterceptor.intercept(ErrorInterceptor.java:26) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:233) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) 五月 30, 2020 9:15:04 下午 org.apache.catalina.session.StoreBase processExpires 严重: Session: 18F8AC0899747787AB7A0BEEFD779179; java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: sd.admin.role.vo.RoleModel at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370) at java.util.HashMap.readObject(HashMap.java:1183)

java 客户端往服务器端传递一个对象时,总是卡死,求解答。

java 客户端往服务器端用ObjectOutputStream的writeObject()传递一个对象时,总是卡死。 java.net.BindException: Address already in use: JVM_Bind java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: sun.applet.AppletAudioClip at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1355) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2000) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1924) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2000) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1924) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371) at GoBangGame.GoBangServer$HandleGoBang.receiveMoveFromPlayer(GoBangServer.java:289) at GoBangGame.GoBangServer$HandleGoBang.run(GoBangServer.java:99) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.NotSerializableException: sun.applet.AppletAudioClip at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348) at GoBangGame.GoBangClient.sendMoveToServer(GoBangClient.java:129) at GoBangGame.GoBangClient.run(GoBangClient.java:104) ... 1 more

JAVA TCP通信,客户端给服务器发送java对象时报错

我在做JAVA TCP 编程时,我想实现客户端A与客户端B之间通过服务器C来通信,但是我通过客户端A给服务器发送消息时,我传送的是一个java对象MsgPackage类对象,我通过ObjectOutputStream.writeObject来传送,但是服务器去读取这个对象时报错了,没有能正确读取到客户端发送过来的对象,请各位大神指教一下。错误的消息是这样: java.lang.ClassNotFoundException: com.client.MsgPackage at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at com.server.ProcRequestThread.run(Server.java:79) at java.lang.Thread.run(Thread.java:619)

Java对象流读取时出错

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.OutputStream; import java.io.Serializable; import java.net.ServerSocket; import java.net.Socket; public class sever { public static void main(String[] args) throws ClassNotFoundException { Socket socket; InputStream is; ObjectInputStream ois; FileOutputStream fos; File file; Object object; User user=null; try { ServerSocket ss=new ServerSocket(9999); socket=ss.accept();System.out.print("hh"); is=socket.getInputStream(); ois=new ObjectInputStream(is); user=(User)ois.readObject(); 这一行有错误。 file=new File("C:/Users/lenovo/Desktop/gg1/a.mp4"); fos=new FileOutputStream(file); while(true){ fos.write(user.getBytes(), 0,user.getBytes().length); fos.flush(); } } catch (IOException e) { } } } class User implements Serializable{ private static final long serialVersionUID = 1L; private byte[] bytes=new byte[1024]; public byte[] getBytes() { return bytes; } public void setBytes(byte[] bytes) { this.bytes = bytes; } } 这个是服务器端,在从对象流中读取对象的时候报错了(错误的地方上面有标识) 错误提示: java.lang.ClassNotFoundException 请求路过的各位大神解答一下

Java中从文件中读取ArrayList报错

java.io.EOFException at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) 代码 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; public class Data { private File file=new File("e:"+File.separator+"message.txt"); private ObjectInputStream ois; private ObjectOutputStream oos; public ArrayList<Message> read() throws FileNotFoundException, IOException{ ArrayList<Message> list=new ArrayList<Message>(); ois=new ObjectInputStream(new FileInputStream(file)); try { list=(ArrayList<Message>) ois.readObject();//报错的位置 ois.close(); } catch (Exception e) { e.printStackTrace(); } return list; } public void write(ArrayList<Message> list){ try { oos=new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(list); oos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

hessian远程访问异常,已尝试过解决方法均无效(下附注),在线等

org.springframework.remoting.RemoteAccessException: Cannot access Hessian remote service at [http://localhost:8080/sso-service/hessian/tempTokenService]; nested exception is java.io.EOFException: r adObject: unexpected end of file at org.springframework.remoting.caucho.HessianClientInterceptor.convertHessianAccessException(HessianClientInterceptor.java:293) at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:265) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy100.getTempTokenByTicketId(Unknown Source) at com.mango.service.passport.api.TempTokenApi.getTempTokenByTicketId(TempTokenApi.java:24) at com.mango.passport.interceptor.SecurityInterceptor.getTicketIdAndSetCookie(SecurityInterceptor.java:135) at com.mango.passport.interceptor.SecurityInterceptor.preHandle(SecurityInterceptor.java:64) at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:958) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.ecog.tingjia.base.CaseInsensitiveParametersFilter.doFilterInternal(CaseInsensitiveParametersFilter.java:20) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Caused by: java.io.EOFException: readObject: unexpected end of file at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2164) at com.caucho.hessian.io.AbstractMapDeserializer.readObject(AbstractMapDeserializer.java:67) at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1835) at com.caucho.hessian.io.Hessian2Input.readReply(Hessian2Input.java:382) at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:195) at com.sun.proxy.$Proxy99.getTempTokenByTicketId(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:248); ***以上是在服务器上抓取的异常.所有依赖的hessian版本4.0.37, jdk1.7/1.8都尝试,据网上查找资料,重载方式已经设置为true, 地址在本地访问显示405是正常.

Java出现了java.io.StreamCorruptedException

java.io.StreamCorruptedException: invalid type code: 00 如题,我是在做模拟ATM的时候遇到问题 具体问题:java.io.StreamCorruptedException: invalid type code: 00 at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at programone.ATMMachine2.fileExist(ATMMachine2.java:36) at programone.ATMMachine2.main(ATMMachine2.java:60)

java FileReader 的 read()方法

用read()方法读取文件中的字符返回为int类型,输出后全为数字,那些数字是什么?重要的是,如何能使输出变成读取的原字符? 例如 : FileReader file = new FileReader("test.txt"); int test = 0; while ((test = file.read()) != -1) { System.out.print(test); } “test.txt”=“abc123456defg” 输出为全看不懂的数字,如何让输出变成“abc123456defg”。

请教一下高手,ObjectOutputStream 类的 writeObject 方法

我在学习网络编程的过程中发现,ObjectOutputStream 类的 writeObject 方法,如果每次都重新 new 一个对象写入,则没有问题; 但如果是最初 new 一个对象,而在每次写入前,改写对象的属性,然后再写入,则每次接收方收到的都是第一次的内容。 本人初学 java ,研究了半天也没搞懂,所以特来向高手请教,示例代码如下: /** 对象类 MsgData.java **/ import java.io.Serializable; public class MsgData implements Serializable { private String from; private String to; private String msg; public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } public String getTo() { return to; } public void setTo(String to) { this.to = to; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String toString() { return from + " 对你说:" + msg; } } /** 发送方(客户端)ClientTest.java **/ import java.io.IOException; import java.io.ObjectOutputStream; import java.net.Socket; import java.util.Scanner; public class ClientTest { public static void main(String[] args) { try { Socket s = new Socket("localhost", 9002); ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()); MsgData iMsg = new MsgData(); iMsg.setFrom("A"); iMsg.setTo("server"); while (true) { Scanner in = new Scanner(System.in); // 如果每次在这里重新 new 对象就是正确的 // MsgData iMsg = new MsgData(); // iMsg.setFrom("A"); // iMsg.setTo("server"); String msg = in.nextLine(); iMsg.setMsg(msg); out.writeObject(iMsg); out.flush(); } } catch (IOException e) { e.printStackTrace(); } } } /** 接收方(服务端)ServerTest.java **/ import java.io.IOException; import java.io.ObjectInputStream; import java.net.ServerSocket; import java.net.Socket; public class ServerTest { public static void main(String[] args) { try { ServerSocket server = new ServerSocket(9002); Socket s = server.accept(); ObjectInputStream in = new ObjectInputStream(s.getInputStream()); while (true) { MsgData iMsg = (MsgData)in.readObject(); System.out.println(iMsg); } } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } 如果使用上面的代码,先运行Server端,再运行Client端,然后在Client端输入123,回车,再输入456,则Server端会显示: A 对你说:123 A 对你说:123 如果按我代码中注释部分所述,把创建对象放到循环里面,再次运行,同样的输入,则Server端会正常显示: A 对你说:123 A 对你说:456 我无法确认究竟是 writeObject 方法的问题,还是 readObject 方法的问题,所以特求助高手,非常感谢!

objectinputstream readobject 为何只能读取第一次写入的值

public class TransEntity implements Serializable//传输信息实体封装类 { private static final long serialVersionUID = 1L; private String operaType;//用户操作类型;如发送文本消息,发送语音消息,发送音频消息 private String responseTags;//网络响应状态;如“登录成功”、“登录失败”、“注册成功”、“注册失败” private String requestTags;//网络请求标记;请求发送文本消息,语音消息,音频消息 private User sender;//发送方; private User receiver;//接收方; private ArrayList<HashMap<String,Object>> buddylist;//好友列表信息; private String time;//系统时间; private ArrayList<HashMap<String,String>> inputGeneralMsgList;//通用信息 private HashMap<String,Object> outGeneralMsgMap; private String path; public String getUserOperaType() { return operaType; } public void setUserOperaType(String operaType) { this.operaType = operaType; } public String getResponseTags() { return responseTags; } public String setResponseTags(String responseTags) { return this.responseTags = responseTags; } public void setRequestTags(String requestTags) { this.requestTags = requestTags; } public String getRequestTags() { return requestTags; } public User getSender() { return sender; } public void setSender(User sender) { this.sender = sender; } public User getReceiver() { return receiver; } public void setReceiver(User receiver) { this.receiver = receiver; } public ArrayList<HashMap<String,Object>> getList() { return buddylist; } public void setList(ArrayList<HashMap<String,Object>> buddylist) { this.buddylist = buddylist; } public String getImagePath() { return path; } public void setImagePath(String path) { this.path = path; } public void setGeneralMessagefrom(ArrayList<HashMap<String,String>> inputGeneralMsgList) { this.inputGeneralMsgList = inputGeneralMsgList; } public ArrayList<HashMap<String,String>> getGeneralMessagefrom() { return inputGeneralMsgList; } public void setGeneralMessageto(HashMap<String,Object> outGeneralMsgMap) { this.outGeneralMsgMap = outGeneralMsgMap; } public HashMap<String,Object> getGeneralMessageto() { return outGeneralMsgMap; } public void setSysTime(String time) { this.time = SysTime.getDateTime(); } public String getSysTime() { return time; } } 服务端核心代码 public class ServerThread extends Thread { private static ObjectInputStream ois = null; private static ObjectOutputStream oos = null; private ArrayList<HashMap<String,Object>> list = null; private ArrayList<HashMap<String,String>> outgeneralMsgList = null; private Socket socket = null; private TransEntity trans = null; private boolean FLAGS_IsFirstLogin = true; private boolean FLAGS_LoginSucess = false; private boolean FLAGS_RegisterSucess = false; private boolean FLAGS_OnLine = false; private User user = null; private User receiver = null; private Timer timer = new Timer(); public ServerThread(Socket socket) { this.socket = socket; try { oos = new ObjectOutputStream(socket.getOutputStream()); ois = new ObjectInputStream(socket.getInputStream()); } catch (IOException e) { e.printStackTrace(); } } public void run() { try { while(true) { if(socket.isClosed() == false && socket.isConnected() == true) { try { if(ois!=null) { trans = (TransEntity) ois.readObject(); } } catch(java.net.SocketException e) { System.out.println("客户端已经关闭。。。。。。。"); break; } catch(ClassNotFoundException e) { System.out.println("--------空指针异常---------"); } catch(java.io.EOFException e) { System.out.println("客户端已经关闭。。。。。。。"); } } if(trans!=null) { user = trans.getSender(); receiver = trans.getReceiver(); if(trans.getUserOperaType()!=null) { System.out.println("----------trans.getUserOperaType() :------------"+(trans.getUserOperaType())); if(FLAGS_IsFirstLogin == true&&(UserOperaType.LOGIN.equals(trans.getUserOperaType()))) { //首次登录,一般情形下的客户端发过来的登录操作请求做处理,非掉线后的自动登录; System.out.println("--------server---socket :------"+(socket)); FLAGS_LoginSucess = setLogin(); } if(FLAGS_LoginSucess) { FLAGS_IsFirstLogin = false; System.out.println("----------trans.getUserOperaType() :------------"+(trans.getUserOperaType())); ......为何此次只能输出第一次读入的数据 if(UserOperaType.SEND_MESSAGE.equals(trans.getUserOperaType())) { System.out.println("-------UserOperaType.SEND_MESSAGE ---------"); System.out.println(trans.getGeneralMessageto().get("outMsg").toString()); if(trans.getGeneralMessageto()!=null)//若getGeneralMessageto()返回值不为空,则可以向数据库写入信息; { System.out.println("-------服务端:---发送方 写入普通信息到数据库,如文字消息;-----------"); SysCtlVar.dbBasicOperation.writeGeneralMessage(trans);// 发送方 写入普通信息到数据库,如文字消息; //trans.setGeneralMessageto(null); } trans.setUserOperaType(null); } oos.writeObject(trans); oos.flush(); } } } } } catch (Exception e) { e.printStackTrace(); } finally { } } } 客户端核心代码 while(SysCtlVar.FlAGS_LoginSuccess) { // System.out.println("--------------while SysCtlVar.FlAGS_LoginSuccess -------------"); try { try { SysCtlVar.trans = (TransEntity)SysCtlVar.ois.readObject(); if(SysCtlVar.inputGeneralMsgList!=null) synchronized(SysCtlVar.inputGeneralMsgList) { SysCtlVar.inputGeneralMsgList = SysCtlVar.trans.getGeneralMessagefrom(); SysCtlVar.inputGeneralMsgList.notify(); } synchronized(SysCtlVar.outGeneralMsgMap) { try { System.out.println("------- SysCtlVar.outGeneralMsgMap.wait----------"); SysCtlVar.outGeneralMsgMap.wait(); //等待直到有输入的时候,才把消息发送出去 System.out.println("---------------客户端: 正在发送消息。。。。。。------------------"); System.out.println("------- SysCtlVar.outGeneralMsgMap:----------"+(SysCtlVar.outGeneralMsgMap.get("outMsg").toString())); SysCtlVar.trans.setUserOperaType(UserOperaType.SEND_MESSAGE); SysCtlVar.trans.setGeneralMessageto(SysCtlVar.outGeneralMsgMap); System.out.println("------- SysCtlVar.trans.getGeneralMessageto():----------"+(SysCtlVar.trans.getGeneralMessageto().get("outMsg").toString())); try { SysCtlVar.oos.writeObject(SysCtlVar.trans); SysCtlVar.oos.flush(); } catch (IOException e) { e.printStackTrace(); } } catch (InterruptedException e) { e.printStackTrace(); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } } catch (StreamCorruptedException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } 客户端 数据输入部分 /** 调试过程中,你将看到客户端输入的消息为h(第一条消息),www(第二条消息),a(第三条消息) 但是服务端只有第二条消息的值; */ //------------------发送消息 ---------- //客户端当前会话任务中,选中的消息接收者; new Thread() { public void run() { synchronized(SysCtlVar.outGeneralMsgMap) { System.out.println("------- 客户端:正在输入要发送的消息----------"); SysCtlVar.outGeneralMsgMap.clear(); SysCtlVar.outGeneralMsgMap.put("outMsg",outMsg); SysCtlVar.outGeneralMsgMap.put("msgRecver", selectedAccount); SysCtlVar.outGeneralMsgMap.put("dateTime",SysTime.getDateTime().toString()); SysCtlVar.outGeneralMsgMap.notify(); //输入完毕,通知发送任务执行 } } }.start(); 调试信息(服务器端) 服务器已启动,正在监听1345端口 ----------trans.getUserOperaType() :------------0 --------server---socket :------Socket[addr=/127.0.0.1,port=38516,localport=1345] ------- list!=null : ---------true [qq]上线了! ----------qq---------- ----------trans.getUserOperaType() :------------0 ----------trans.getUserOperaType() :------------6 ----------trans.getUserOperaType() :------------6 -------------UserOperaType.GET_AVATARS------------6 我想从服务器获取头像 ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ---------------问题补充--------------- 单步调试,客户端的输出流正确发送了每一次的客户端输入数据(36分钟前)删除 对于单步调试追踪的结果:客户端每一次发送的trans(它是TransEntity的实例,被序列化的消息实体对象)都是正确的(即,与客户端输入值相同)。但是服务端有ObjectInputStream读入的trans(它也是TransEntity的实例,被序列化的消息实体对象)却没有改变始终是第一次的值

请问大家见过这个异常吗java.io.StreamCorruptedException: invalid stream header: 7371007E异常求解

代码如下 ``` package Chat; import java.io.IOException; import java.io.ObjectInputStream; import java.net.Socket; public class ClientConServerThread extends Thread{ private Socket client; public ClientConServerThread(Socket client){ this.client=client; } public Socket getClient() { return client; } public void run(){ while(true){ try { ObjectInputStream ois = new ObjectInputStream(client.getInputStream());//这里出现了异常 Message m=(Message)ois.readObject(); System.out.println(m.getCon()); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } } } ``` 异常如下 java.io.StreamCorruptedException: invalid stream header: 7371007E at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 00007400 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 01417400 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 0C323031 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 39303033 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 30313134 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 3274001C at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 54756520 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 41707220 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 32382031 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 353A3436 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 3A313920 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 43535420 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 32303230 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 74000C32 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 30313930 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) java.io.StreamCorruptedException: invalid stream header: 30333031 at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:877) at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:350) at Chat.ClientConServerThread.run(ClientConServerThread.java:20) Process finished with exit code -1

用eclipse编java代码的控制台出现的uid兼容解决

javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -1030230214076481435, local class serialVersionUID = 3742318830738515599 at java.io.ObjectStreamClass.initNonProxy(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readArray(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.defaultReadFields(Unknown Source) at java.io.ObjectInputStream.readSerialData(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.defaultReadFields(Unknown Source) at java.io.ObjectInputStream.readSerialData(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at com.lzw.MainFrame.<init>(MainFrame.java:92) at com.lzw.MainFrame$1.run(MainFrame.java:120) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) java.lang.IllegalArgumentException: model must be non null at javax.swing.JList.setModel(Unknown Source) at com.lzw.MainFrame.<init>(MainFrame.java:100) at com.lzw.MainFrame$1.run(MainFrame.java:120) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) 怎么解决呢

SCJP一道选择题,为什么CardPlayer c2 = (CardPlayer) is.readObject();单独创建父类对象?

代码如下: ``` class Player { Player() { System.out.print("p"); } } public class CardPlayer extends Player implements Serializable { CardPlayer() { System.out.print("c"); } public static void main(String[] args) { CardPlayer c1 = new CardPlayer(); try { FileOutputStream fos = new FileOutputStream("play.txt"); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(c1); os.close(); FileInputStream fis = new FileInputStream("play.txt"); ObjectInputStream is = new ObjectInputStream(fis); CardPlayer c2 = (CardPlayer) is.readObject(); is.close(); } catch (Exception x) { } } } ``` 为什么最后输出结果是“pcp”而不是“pcc”?

读取文件内容出现java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: elective.system.Elective错误

1.在读取文件中的内容时出现标题错误,Elective类已经继承Serializable接口 ```package elective.system; import java.io.File; import java.io.Serializable; import java.util.ArrayList; /* 选修课程类 */ public class Elective implements Serializable { private int class_num; //选修课程编号 private String class_nature; //课程类别 private String class_name; //选修课名称 private String class_teacher; //课程教师 private int class_credit; //课程学分 private String class_time; //课程起止周 private String class_daily_time; //课程日常上课时间 private String class_school; //课程承办的二级学院 private int class_person_num; //课程人数 private String class_note; //课程备注 //无参构造方法 public Elective() { } //有参构造方法 public Elective(int class_num, String class_nature, String class_name, String class_teacher, int class_credit, String class_time, String class_daily_time, String class_school, int class_person_num, String class_note) { this.class_num = class_num; this.class_nature = class_nature; this.class_name = class_name; this.class_teacher = class_teacher; this.class_credit = class_credit; this.class_time = class_time; this.class_daily_time = class_daily_time; this.class_school = class_school; this.class_person_num = class_person_num; this.class_note = class_note; } //getter和setter方法 public int getClass_person_num() { return class_person_num; } public void setClass_person_num(int class_person_num) { this.class_person_num = class_person_num; } public int getClass_num() { return class_num; } public void setClass_num(int class_num) { this.class_num = class_num; } public String getClass_name() { return class_name; } public void setClass_name(String class_name) { this.class_name = class_name; } public String getClass_teacher() { return class_teacher; } public void setClass_teacher(String class_teacher) { this.class_teacher = class_teacher; } public int getClass_credit() { return class_credit; } public void setClass_credit(int class_credit) { this.class_credit = class_credit; } public String getClass_time() { return class_time; } public void setClass_time(String class_time) { this.class_time = class_time; } public String getClass_daily_time() { return class_daily_time; } public void setClass_daily_time(String class_daily_time) { this.class_daily_time = class_daily_time; } public String getClass_nature() { return class_nature; } public void setClass_nature(String class_nature) { this.class_nature = class_nature; } public String getClass_note() { return class_note; } public void setClass_note(String class_note) { this.class_note = class_note; } public String getClass_school() { return class_school; } public void setClass_school(String class_school) { this.class_school = class_school; } //增加选修课程 public boolean add_class(Elective elective){ boolean flag = false; File file = new File("D:\\IdeaProjects\\basic-code\\01-code\\选修课程表\\class.txt"); OperateFile operateFile = new OperateFile(); try{ operateFile.save(elective,file); flag = true; }catch (Exception e){ e.printStackTrace(); } return flag; } //查看已有选修课程 public ArrayList<Elective> look_class(){ ArrayList<Elective> list = new ArrayList<>(); File file = new File("D:\\IdeaProjects\\basic-code\\01-code\\选修课程表\\class.txt"); OperateFile operateFile = new OperateFile(); try{ list = operateFile.load(file); }catch (Exception e){ e.printStackTrace(); } return list; } @Override public String toString() { return "课程编号:" + class_num + ", 课程类别:" + class_nature + ", 课程名称:" + class_name + ", 授课教师:" + class_teacher + ", 学分:" + class_credit + ", 课程起止周:" + class_time + ", 课程上课时间:" + class_daily_time + ", 课程承办学院:" + class_school+ ", 课程备注:" + class_note; } } 这是文件保存和读取类 ``` package elective.system; import java.io.*; import java.util.ArrayList; /* 文件操作类 */ public class OperateFile implements Serializable{ public boolean save(Object e,File file) throws Exception{ // 保存对象 boolean flag = false ; // 定义操作标志位 FileOutputStream fos = new FileOutputStream(file,true); //采用追加方式写入数据 if(file.length()<1){ ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(e); flag = true; oos.close(); }else{ MyObjectOutputStream mos = new MyObjectOutputStream(fos); mos.writeObject(e); flag = true; mos.close(); } return flag ; } public ArrayList load(File file) throws Exception{ // 读取对象 ArrayList<Object> list = new ArrayList(); FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); while(fis.available()>0){ Object p = ois.readObject(); list.add(p); } ois.close(); return list; } } class MyObjectOutputStream extends ObjectOutputStream{ public MyObjectOutputStream(OutputStream out) throws IOException { super(out); } public void writeStreamHeader() throws IOException{ return; } } ``` 这是操作: Elective elective = new Elective(); ArrayList<Elective> list = elective.look_class(); for(Elective et : list){ System.out.println(et.toString()); } ``` 请问各位大佬这是为什么呢?

tomcat启动报java.io.EOFException,不影响运行

java.io.EOFException at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2577) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at net.bull.javamelody.CounterStorage.readFromFile(CounterStorage.java:110) at net.bull.javamelody.Counter.readFromFile(Counter.java:883) at net.bull.javamelody.Collector.<init>(Collector.java:111) at net.bull.javamelody.FilterContext.<init>(FilterContext.java:102) at net.bull.javamelody.MonitoringFilter.init(MonitoringFilter.java:111) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258) at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722)

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

抖音上很火的时钟效果

反正,我的抖音没人看,别人都有几十万个赞什么的。 发到CSDN上来,大家交流下~ 主要用到原生态的 JS+CSS3。 具体不解释了,看注释: &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Title&lt;/tit...

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

培训班出来的人后来都怎么样了?(二)

接着上回说,培训班学习生涯结束了。后面每天就是无休止的背面试题,不是没有头脑的背,培训公司还是有方法的,现在回想当时背的面试题好像都用上了,也被问到了。回头找找面试题,当时都是打印下来天天看,天天背。 不理解呢也要背,面试造飞机,上班拧螺丝。班里的同学开始四处投简历面试了,很快就有面试成功的,刚开始一个,然后越来越多。不知道是什么原因,尝到胜利果实的童鞋,不满足于自己通过的公司,嫌薪水要少了,选择...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

推荐9个能让你看一天的网站

分享的这9个保证另你意外的网站,每个都非常实用!非常干货!毫不客气的说,这些网站最少值10万块钱。 利用好这些网站,会让你各方面的技能都得到成长,不说让你走上人生巅峰,但对比现在的你,在眼界、学识、技能方面都有质的飞跃。 一、AIRPANO 传送门:https://www.airpano.com/360photo_list.php 这是一个可以躺在家里,就能环游世界的神奇网站。 世界那么大,绝大多...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

什么是a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站?00后的世界我不懂!

A站 AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站。A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量互动弹幕,是中国弹幕文化的发源地;拥有大量超粘性的用户群体,产生输出了金坷垃、鬼畜全明星、我的滑板鞋、小苹果等大量网络流行文化,也是中国二次元文化的发源地。 B站 全称“哔哩哔哩(bilibili...

十个摸鱼,哦,不对,是炫酷(可以玩一整天)的网站!!!

文章目录前言正文**1、Kaspersky Cyberthreat real-time map****2、Finding Home****3、Silk – Interactive Generative Art****4、Liquid Particles 3D****5、WINDOWS93****6、Staggering Beauty****7、Ostagram图片生成器网址****8、全历史网址*...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

大厂的 404 页面都长啥样?最后一个笑了...

每天浏览各大网站,难免会碰到404页面啊。你注意过404页面么?猿妹搜罗来了下面这些知名网站的404页面,以供大家欣赏,看看哪个网站更有创意: 正在上传…重新上传取消 腾讯 正在上传…重新上传取消 网易 淘宝 百度 新浪微博 正在上传…重新上传取消 新浪 京东 优酷 腾讯视频 搜...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

一场疫情,炸出了退休的COBOL程序员

COBOL编程语言,估计大多数程序员从没听说过,我这样的编程老司机,也是只闻其名,从未一睹芳容。出门问了问度娘,答案如下:COBOL语言,是一种面向过程的高级程序设计语言,主要用于数据...

爬虫(101)爬点重口味的

小弟最近在学校无聊的很哪,浏览网页突然看到一张图片,都快流鼻血。。。然后小弟冥思苦想,得干一点有趣的事情python 爬虫库安装https://s.taobao.com/api?_ks...

讲真,这两款idea插件,能治愈你英语不好的病

时不时就有小伙伴问我,“二哥,能推荐一款 IDE 吗?”你看这话问的,现在搞 Java 的不都在用 Intellij IDEA 吗,还用得着推荐(我已经和 Eclipse 分手了)。然后小伙伴又说,“二哥,IDEA 支持中文吗?我英语不太好。”你看这话问的,搞编程的,英语不好是硬伤啊! 不过,随着 IDEA 最新版(版本号是 2020.1)的发布,英语不好的病可以彻底治愈了。为什么这么说呢?因为 ...

在拼多多上班,是一种什么样的体验?我心态崩了呀!

之前有很多读者咨询我:武哥,在拼多多上班是一种什么样的体验?由于一直很忙,没抽出时间来和大家分享。上周末特地花点时间来写了一篇文章,跟大家分享一下拼多多的日常。 1. 倒时差的作息 可能很多小伙伴都听说了,拼多多加班很严重。这怎么说呢?作息上确实和其他公司有点区别,大家知道 996,那么自然也就能理解拼多多的“11 11 6”了。 所以当很多小伙伴早上出门时,他们是这样的: 我们是这样的: 当...

又一起程序员被抓事件

就在昨天互联网又发生一起让人心酸的程序员犯罪事件,著名的百度不限速下载软件 Pandownload PC 版作者被警方抓获。案件大致是这样的:软件的作者不仅非法盗取用户数据,还在QQ群进...

瑞德西韦重症用药结果再曝光,上百名重症一周内好转,股价大涨19%

郭一璞 发自 凹非寺量子位 报道 | 公众号 QbitAI期盼已久的瑞德西韦临床数据,现在“偷跑”了。在芝加哥大学医学院的临床试验中,125名病人参与,大部分人都已经出院,其中只有2名病...

应聘3万的职位,有必要这么刁难我么。。。沙雕。。。

又一次被面试官带到坑里面了。面试官:springmvc用过么?我:用过啊,经常用呢面试官:springmvc中为什么需要用父子容器?我:嗯。。。没听明白你说的什么。面试官:就是contr...

Vue商城——详情页功能

详情页实现思路 点击商品进去详情页,根据点击请求更加详细的信息,要传过来goodsItem的iid,根据id去服务器请求更加详细的信息;配置路由映射关系,点击进行跳转,带参数传递跳转 itemClick(){ this.$router.push('/detail/'+this.goodsItem.iid) /* this.$router.push({ ...

太狠了,疫情期间面试,一个问题砍了我5000!

疫情期间找工作确实有点难度,想拿到满意的薪资,确实要点实力啊!面试官:Spring中的@Value用过么,介绍一下我:@Value可以标注在字段上面,可以将外部配置文件中的数据,比如可以...

自学编程的 6 个致命误区

嗨,小伙伴们大家好,我是沉默王二。本篇文章来和大家聊聊自学编程中的一些误区——这是我在 B 站上看了羊哥的一期视频后有感而发的文章。因为确实有很多读者也曾私信问过我这些方面的问题,很有代表性,所以我就结合自己的亲身体会来谈一谈,希望对小伙伴们有所启发。 01、追求时髦 所谓基础不牢,地动山摇啊。可很多小伙伴压根就没注意过这个问题,市面上出什么新鲜的技术就想去尝试,结果把自己学的乱七八糟,心灰意冷...

相关热词 c# 局部 截图 页面 c#实现简单的文件管理器 c# where c# 取文件夹路径 c# 对比 当天 c# fir 滤波器 c# 和站 队列 c# txt 去空格 c#移除其他类事件 c# 自动截屏
立即提问