Java io使用readUTF()报 java.io.EOFException Create breakpoint
查了很多,都解决不了。 可以不报异常。但是输出的是乱码。
ObjectOutputStream
oos.write(10); oos.writeDouble(Math.random()); oos.writeChar('a'); oos.writeBoolean(true); oos.writeUTF("你好!java!"); oos.flush();
ObjectInputStream
读取出来是错误的
自己解决的
System.out.println(new String(ois.readLine().getBytes("ISO-8859-1"),"utf-8"));
但是输出不行。。。
请老师解答!~
老师,创建的外部的DTD文件复制后为什么直接变成黑色的还比起作用呢,视频的老师直接就能用了
底层分析——添加元素:
分析过程图形有吗?有图形可以更好的理解.
xml:
<?xml version="1.0" encoding="UTF-8"?> <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd"> <book id="1001"> <name>java开发实战</name> <author>张小三</author> <price>98.5</price> </book> <book id="1002"> <name>mysql从删库到跑路</name> <author>王一一</author> <price>89.7</price> </book> </books>
xsd:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="books"> <xs:complexType> <xs:sequence> <xs:element name="book" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"></xs:element> <xs:element name="author" type="xs:string"></xs:element> <xs:element name="price" type="xs:double"></xs:element> </xs:sequence> <xs:attribute name="id" type="xs:positiveInteger" use="required"></xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Test:
package com.bjsxt; import org.xml.sax.SAXException; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import java.io.File; import java.io.IOException; public class Test { public static void main(String[] args) throws SAXException { //创建SchemaFactory工厂 SchemaFactory sch = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema-instance"); //验证文件对象 File schemaFile = new File("book.xsd"); //利用SchemaFactory工厂对象,接收验证的文件对象,生成Schema对象 Schema schema = sch.newSchema(schemaFile); //产生对此Schema的验证器 Validator validator = schema.newValidator(); //要验证的数据(准备数据源) Source source = new StreamSource("book.xml"); //开始验证 try { validator.validate(source); System.out.println("成功"); } catch (IOException e) { e.printStackTrace(); System.out.println("失败"); } } }
文件位置:
运行时的错误:
pw = new PrintWriter(socket.getInputStream)为什么这个时候,不要将socket.getInputStream转化成字符,是PrintWriter自动能将字节流转换成字符流嘛?
老师,我jar包可以打开,但这个不行,为什么啊
老师,那意思就是说list的用法set接口也能有是吗?
为什么递归函数不能传入file参数
import java.io.File; public class TestFile { public static void main(String[] args) { File f = new File("D:\\学习资料"); printFile(f, 0); } public static void printFile(File file,int level){ for(int i=0;i<level;i++){ System.out.print("-"); } //获取目录名 System.out.println(file.getName()); //进行判断,如果是目录,就获取列表 if(file.isDirectory()){ File[] fileList = file.listFiles(); for(File temp:fileList){ System.out.println(temp); } printFile(file, level+1); } } }
为什么把参数传入成file会变成死循环
老师,在第一次运行echoserver 和goodtcp的时候,goodtcp可以正常运行。但是echoserver报错,java.net.BindException: Address already in use: bind
第二次运行goodtcp,goodtcp类报错 java.net.ConnectException: Connection refused: connect
这是什么原因造成的,谢谢。
新建文件夹.rar
同样的JAVA代码和同样的HTML代码,为什么我这边获取不到浏览器的信息?
package com.bjsxt.server; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; public class Server2 { public static void main(String[] args) { //(1)创建ServerSocket对象 ServerSocket server=null; //(2)监听是否有客户端发送请求 Socket client=null; BufferedReader br=null; try { server = new ServerSocket(8888); client = server.accept(); //获取来自浏览器的请求信息 br=new BufferedReader(new InputStreamReader(client.getInputStream(), "utf-8")); String str=null; while((str=br.readLine()).length()>0){ System.out.println(str); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ //(6)关闭流 IOClose.closeAll(br,client,server); } } }
<html> <title> Tomcat </title> <body> <form action="http://lcoalhost:8888/log" method="get"> <h1>hello world</h1 <p>用户名:<input type="text" id="uname" name="username" /></p> <p>密码:<input type="password" id="pwd" name="password" /></p> <p><input type="submit" value="登陆" /></p> </form> </body> </html>
我的代码一直在跑,完全没有阻塞效果,跑了几千都还在跑
sockeydemo.zip老师能帮我看看那点出问题了吗?
//B/S结构 浏览器与服务器 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; public class Server2 { public static void main(String[] args) { //1)创建ServerSocket对象 ServerSocket server=null; //2)监听是否有客户端发送请求 Socket client=null; BufferedReader br=null; try { server = new ServerSocket(8888); client = server.accept(); //获取来自浏览器的请求信息 br=new BufferedReader(new InputStreamReader(client.getInputStream(),"utf-8")); String str=null; while((str=br.readLine()).length()>0){ str=new String(str.getBytes("ISO-8859-1"),"utf-8");//ISO-8859-1 System.out.println(str); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { //6)关闭流 IOClose.closeAll(br,client,server); } } }
老师,这个结果还是乱码,网上也查了,也已经试了好多种可能,还是乱码,怎么改?
老师这一段代码老师的serlvet我不理解是老师故意这样写的还是写错了。
老师,以下是我的代码,请问为什么会报错?请问是什么错误?
package com.bjsxt.url; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; public class TestURL2 { public static void main(String[] args) throws IOException { /**网络爬虫 * (1)从网络上获取资源 www.baidu.com * (2)存储到本地 * */ //(1)创建URL对象 URL url=new URL("https://www.baidu.com");//主页资源 //(2)获取字节输入流 InputStream is=url.openStream(); //(3)缓冲流 BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8")); //(4)存储到本地 BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("index.html"),"utf-8")); //(5)边读边写 String line=null; while((line=br.readLine())!=null){ bw.write(line); bw.newLine(); bw.flush(); } //(6)关闭流 bw.close(); br.close(); } }
报错内容:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:320) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258) at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:641) at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:460) at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:360) at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392) at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:441) at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:419) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:177) at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1180) at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1091) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567) at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1581) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246) at java.base/java.net.URL.openStream(URL.java:1140) at com.bjsxt.url.TestURL2.main(TestURL2.java:21) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:384) at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:289) at java.base/sun.security.validator.Validator.validate(Validator.java:264) at java.base/sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:321) at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221) at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129) at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:625) ... 17 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297) at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:379) ... 23 more
请老师看一下,代码应该没问题
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637