会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132849个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 2417楼

package com.bjsxt.array;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class Test {
	public static void main(String[] args) {
		byte [] buf=write();//调用写对象的方法
		//调用读对象的方法
		read(buf);
	}
	public static byte[] write(){
		//创建字节数组流对象
		ByteArrayOutputStream baos=null;
		ObjectOutputStream oos=null;
		
		try {
			baos=new ByteArrayOutputStream();//创建字节数组流对象,目的地是字节数组,底层创建一个长度数为32的字节数组
			oos=new ObjectOutputStream(baos);
			oos.writeInt(98);
			oos.writeDouble(98.5);
			oos.writeChar('a');
			oos.writeBoolean(false);
			oos.writeObject(new Date(1000));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			//关闭流
			if (oos!=null) {
				try {
					oos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		return baos.toByteArray();
	}
	public static void read(byte [] buf){
		ByteArrayInputStream bais=null;
		ObjectInputStream ois=null;
		//创建对象
		try {
			bais=new ByteArrayInputStream(buf); //数据源是byte类型的数组
			ois=new ObjectInputStream(bais);
			
			//读数据
			System.out.println(ois.readInt());
			System.out.println(ois.readDouble());
			System.out.println(ois.readChar());
			System.out.println(ois.readBoolean());
			System.out.println(ois.readObject());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
		
			//关闭流
			if(ois!=null){
				try {
					ois.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}

这里主函数去调用写出方法时是这样调用的

byte [] buf=write();//调用写对象的方法

有什么说法吗   第一次见这种写法

JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 2422楼

已经导入jaxen包了,为啥还是会出现找不包的异常,用的是IDEA

package com.zheng.TestXML;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.io.File;

public class TextXpath {
    public static void main(String[] args) throws DocumentException {
        //1) 创建 SAXReader 对象
        SAXReader reader = new SAXReader();
        //2) 调用 read 方法
        Document doc = reader.read(new File("books.xml"));
        //3)
        Node node = doc.selectSingleNode("//name");
        System.out.println("节点的名称:"+node.getName()+"节点的值"+node.getText());
    }
}

"E:\学习软件大集合\IDEA\IntelliJ IDEA 2019.3.2\jbr\bin\java.exe" "-javaagent:E:\学习软件大集合\IDEA\IntelliJ IDEA 2019.3.2\lib\idea_rt.jar=49244:E:\学习软件大集合\IDEA\IntelliJ IDEA 2019.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\zheng\Desktop\mycode\Process\out\production\XML;C:\Users\zheng\Desktop\mycode\Process\lib\jdom.jar;C:\Users\zheng\Desktop\mycode\Process\lib\dom4j-1.6.1.jar com.zheng.TestXML.TextXpath
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.dom4j.io.SAXContentHandler (file:/C:/Users/zheng/Desktop/mycode/Process/lib/dom4j-1.6.1.jar) to method com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy.getEncoding()
WARNING: Please consider reporting this to the maintainers of org.dom4j.io.SAXContentHandler
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
	at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
	at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
	at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:183)
	at com.zheng.TestXML.TextXpath.main(TextXpath.java:22)
Caused by: java.lang.ClassNotFoundException: org.jaxen.JaxenException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 4 more


JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 2423楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 2425楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 2426楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 2427楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 2428楼

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器 2429楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 2430楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637