随机访问流and合并流and序列化流andPropertoes
来源:互联网 发布:淘宝描述不符怎么处理 编辑:程序博客网 时间:2024/06/06 20:00
class RandomAccessTest {// 多线程 下载文件 随机访问流public static void main(String[] args) {RandomAccessFile f = null;try{// String name,String mode 模式(读写)f =new RandomAccessFile("D:\\xx.txt","rw");long pointer =f.getFilePointer();f.write("牧佑叔叔_");pointer +=",牧佑叔叔".getBytes();f.seek(pointer - "叔叔".getBytes.length);f.seek(1);//操作指针。从哪开始插数据0,1,2,3字节 // 所以转换//f.seek("牧".getBytes().length());f.wirte("么么哒");}catch(IOException e){} finally{if(f !=null){try{f.close();}catch(IOException ex){}}}}}
class SequenceInputStream {// 合并流。将两个文件合并到一个文件public static void main(String[] args) thorws IoException{//String流ByteArrayInputStream bis = new ByteArrayInputStream("牧佑".getBytes());ByteArrayInputStream bis2 = new ByteArrayInputStream("叔叔".getBytes());SequenceInputStream sis = new SequenceInputStream(bis,bis2);StringBuilder sb = new StringBuilder();//放到byte数组里面byte[] buf = new byte[1024];int len = -1;while((len =sis.reder(buf))!= -1){byte[] tm = new byte[len];//System.arraycopy(buf,0,tm,0,len);sb.append(new String(buf,0,len));}System.out.println(sb.toString());}}
class ObjectOutputStream and ObjectInputStream {// 序列化流 操作对象流化 public static void main(String[] args) throws FileNotFoundException{FileOutputStream fos = new FileOutputStream("D:\\xx.txt");// 对象必须继承序列化接口//如果对象字段不需要 系列化 使用 transient声明即可// private transient String name;Student s = new Student();s.setMomo("腹股沟");s.setAff("好像傻");ObjectOutputStream oos = new ObjectOutputStream(fos);oos.writerObject(s);oos.flush();oos.close();FileInputStream f = new FileInputStream("D:\\xx.txt");ObjectInputStream i = new ObjectInputStream(f);Student sfg = (Student)i.readObject();System.err.println(sfg.getMomo);i.close();}}
class PropertiesDemo {// Propertoes 与 IO 结合public static void main(String[] args) throws IOException{Reader r = new Reader("D:\\xt.properties");// 新IO 可以用pathsPath path = Paths.get("d:","pro","sd.txt");Properties pro = new Properties();pro.load(r);pro.close();Enumeration<String>name = (Enumeration<String>)pro.propertyName();while(name.hasMoreElements){String key = name.nextElements()'Sytem.out.println("key:"+key);System.out.println("values:"+pro.getProperty(key));//读Writer e = new FileWriter("D:\\xt.properties");pro.setProperty("student","牧佑");pro.store(e,"新增");e.close();}}}
阅读全文
0 0
- 随机访问流and合并流and序列化流andPropertoes
- javaseday24(文件切割器 合并 序列化 随机访问文件特殊的流 管道流)
- IO流_数据操作流、内存操作流、打印流、标准输入输出流、随机访问流、合并流、序列化流、Properties、总结
- JAVA基础再回首(二十三)——操作基本数据类型的流、内存操作流、打印流、随机访问流、合并流、序列化流
- 22 API-IO流(登陆注册IO版案例,数据操作流,内存操作流,打印流,标准输入输出流,:随机访问流,合并流,序列化流),Properties,NIO)
- Java基础-22总结登录注册IO版,数据操作流,内存操作流,打印流,标准输入输出流,转换流,随机访问流,合并流,序列化流,Properties
- 【JavaSE学习笔记】IO流06_其他常用流(基本数据类型流、内存操作流、打印流、标准流、随机访问流、合并流、序列化与反序列化流)、属性集合类Properties
- 合并(序列)流
- 流随机访问
- 随机访问流:
- 随机访问流RandomAccessFile
- 黑马程序员--------java IO流 File类、Properties、打印流、合并流、对象序列化、随机读写、字符编码
- IO 之键盘录入与控制台输出,随机访问流,合并流
- java__io__序列流(合并MP3)和对象序列化
- 黑马程序员_<<IO扩展对象和编码(序列化,管道流,字节(符)数组),随机访问文件>>
- 黑马程序员_<<IO扩展对象和编码(序列化,管道流,字节(符)数组),随机访问文件>>
- C++ 流的随机访问
- java: 随机访问流RandomAccessFile
- spring boot基础之统一异常处理(小demo)
- 10033---Redis 为什么使用单进程单线程方式也这么快
- Caused by: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
- 大数据个人笔记(一)
- sqlmap 随笔 羽翼sqlmap学习笔记
- 随机访问流and合并流and序列化流andPropertoes
- wireshark抓包图解 TCP三次握手/四次挥手详解
- MVC各个 部分有哪些技术实现
- 04wxWidgets多线程
- Android中的Window 如何管理?
- 浅谈Java的Fork/Join并发框架
- Java密码学
- Unity3D实时显示FPS(移动端测试神器)
- Java基础之双列集合Map