六,IO系统
六,IO系统
一,数据源
1,数据源--管道确认使用那根管道--节点流
2,先确定管道在tey中new出管道,new出后就写关闭代码,写完关闭代码在写中间代码
3,取数据和放数据结束语句必须有两个,不能写在一个try中
4,fout.flush();//冲刷,用来强制执行完后才能执行下一步
5,对象的序列化和反序列化;
1,将输入的二进制对象流转换为对象(不管从哪来)
2,把对象以二进制流的形式输出(不管输出到哪)
3,transient();修饰的属性值不参与序列化
二,字节流(byte)二进制数据,我们看不懂,什么数据都可以传,包括字符流
1,字节输入流;(inputstream),字节输出流;(outputstream)
例;
FileInputStream fin = null;
FileOutputStream fout = null;
try {
fin = new FileInputStream("D:/lileihanmeimei.mp3");
fout = new FileOutputStream("F:/my.mp3");
byte[] b = new byte[1024];
int length = 0;
while((length = fin.read(b)) != -1){
fout.write(b,0,length);
fout.flush();//冲刷
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fin != null){
try {
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fout != null){
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2,对象反序列化:(ObjectOutputStream)将输入的二进制对象流转换为对象
例;
StudentBean stu = new StudentBean("小白", 25);
stu.setHomeAddress(new AddressBean("中国", "四川", "绵阳"));
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream("stu.data"));
oos.writeObject(stu);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(oos != null){
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3,对象序列化(ObjectInputStream)---把对象以二进制流的形式输出
例;
StudentBean stu = null;
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream("stu.data"));
stu = (StudentBean)ois.readObject();
stu.study();
System.out.println(stu.getAge());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally{
if(ois != null){
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
三,字符流(char)文本数据,我们看得懂的,只能传字符流
1,字符输入流(reader)
例;
String poem = "";
FileReader fr = null;
try {
fr = new FileReader("poem.txt");
int c = 0;
while((c = fr.read()) != -1){
poem += (char)c;//取字符
}
System.out.println(poem);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fr != null){
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2,字符输出流(writer)
例;
String poem = "床前明月光,地上疑似霜。";
1、确定管道
FileWriter fw = null;
try {
fw = new FileWriter("poem.txt");
2、操作管道
fw.write(poem);//放字符
} catch (IOException e) {
e.printStackTrace();
} finally{
3、关闭管道
if(fw != null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
四,file来自io包是Java中专门用于封装表示文件/文件夹的类型
File是Java中专门用来封装表示文件/文件夹的类型
1,File表示文件
File file = new File("F:/my.mp3");
ile file1 = new File("F:/hello.txt");
File file2 = new File("D:/world.txt");
System.out.println(file.getName());
System.out.println(file.getPath());
System.out.println(file.getParent());
System.out.println(file.length());
System.out.println(new Date(file.lastModified()));
try {
if(!file1.exists()){
file1.createNewFile();
}else{
file1.renameTo(file2);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(file1.canWrite());
System.out.println(file1.isHidden());
2,File表示文件夹
File dir = new File("D:/tools");
if(dir.isDirectory()){
String[] subStrs = dir.list();
for(String sub : subStrs){
System.out.println(sub);
}
File[] subFiles = dir.listFiles();
for(File sub : subFiles){
if(sub.isHidden()){
System.out.println(sub.getName());
}
}
}
六,IO系统
一,数据源
1,数据源--管道确认使用那根管道--节点流
2,先确定管道在tey中new出管道,new出后就写关闭代码,写完关闭代码在写中间代码
3,取数据和放数据结束语句必须有两个,不能写在一个try中
4,fout.flush();//冲刷,用来强制执行完后才能执行下一步
5,对象的序列化和反序列化;
1,将输入的二进制对象流转换为对象(不管从哪来)
2,把对象以二进制流的形式输出(不管输出到哪)
3,transient();修饰的属性值不参与序列化
二,字节流(byte)二进制数据,我们看不懂,什么数据都可以传,包括字符流
1,字节输入流;(inputstream),字节输出流;(outputstream)
例;
FileInputStream fin = null;
FileOutputStream fout = null;
try {
fin = new FileInputStream("D:/lileihanmeimei.mp3");
fout = new FileOutputStream("F:/my.mp3");
byte[] b = new byte[1024];
int length = 0;
while((length = fin.read(b)) != -1){
fout.write(b,0,length);
fout.flush();//冲刷
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fin != null){
try {
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fout != null){
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2,对象反序列化:(ObjectOutputStream)将输入的二进制对象流转换为对象
例;
StudentBean stu = new StudentBean("小白", 25);
stu.setHomeAddress(new AddressBean("中国", "四川", "绵阳"));
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream("stu.data"));
oos.writeObject(stu);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(oos != null){
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3,对象序列化(ObjectInputStream)---把对象以二进制流的形式输出
例;
StudentBean stu = null;
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream("stu.data"));
stu = (StudentBean)ois.readObject();
stu.study();
System.out.println(stu.getAge());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally{
if(ois != null){
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
三,字符流(char)文本数据,我们看得懂的,只能传字符流
1,字符输入流(reader)
例;
String poem = "";
FileReader fr = null;
try {
fr = new FileReader("poem.txt");
int c = 0;
while((c = fr.read()) != -1){
poem += (char)c;//取字符
}
System.out.println(poem);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fr != null){
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2,字符输出流(writer)
例;
String poem = "床前明月光,地上疑似霜。";
1、确定管道
FileWriter fw = null;
try {
fw = new FileWriter("poem.txt");
2、操作管道
fw.write(poem);//放字符
} catch (IOException e) {
e.printStackTrace();
} finally{
3、关闭管道
if(fw != null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
四,file来自io包是Java中专门用于封装表示文件/文件夹的类型
File是Java中专门用来封装表示文件/文件夹的类型
1,File表示文件
File file = new File("F:/my.mp3");
ile file1 = new File("F:/hello.txt");
File file2 = new File("D:/world.txt");
System.out.println(file.getName());
System.out.println(file.getPath());
System.out.println(file.getParent());
System.out.println(file.length());
System.out.println(new Date(file.lastModified()));
try {
if(!file1.exists()){
file1.createNewFile();
}else{
file1.renameTo(file2);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(file1.canWrite());
System.out.println(file1.isHidden());
2,File表示文件夹
File dir = new File("D:/tools");
if(dir.isDirectory()){
String[] subStrs = dir.list();
for(String sub : subStrs){
System.out.println(sub);
}
File[] subFiles = dir.listFiles();
for(File sub : subFiles){
if(sub.isHidden()){
System.out.println(sub.getName());
}
}
}
六,IO系统的更多相关文章
- java中的io系统详解 - ilibaba的专栏 - 博客频道 - CSDN.NET
java中的io系统详解 - ilibaba的专栏 - 博客频道 - CSDN.NET 亲,“社区之星”已经一周岁了! 社区福利快来领取免费参加MDCC大会机会哦 Tag功能介绍—我们 ...
- 从零开始山寨Caffe·拾贰:IO系统(四)
消费者 回忆:生产者提供产品的接口 在第捌章,IO系统(二)中,生产者DataReader提供了外部消费接口: class DataReader { public: ......... Blockin ...
- 从零开始山寨Caffe·陆:IO系统(一)
你说你学过操作系统这门课?写个无Bug的生产者和消费者模型试试! ——你真的学好了操作系统这门课嘛? 在第壹章,展示过这样图: 其中,左半部分构成了新版Caffe最恼人.最庞大的IO系统. 也是历来最 ...
- io系统
一.浅谈io系统 io系统的结构化思想是:输入-转换流-装饰器-输出. 对于字节流来说,常见的结构类为: package com.handchina.yunmart.middleware.servic ...
- 彻底明白Java的IO系统
java学习:彻底明白Java的IO系统 文章来源:互联网 一. Input和Output1. stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源.在Java的IO中,所有 ...
- 什么是PROFINET IO系统的实时性
实时系统是指系统能及时响应外部事件的请求,在规定的时间内完成对该事件的处理,并控制所有实时任务协调一致的运行. PROFINET IO系统的实时性就是指当有一个外部事件发生时,从输入信号到传输.到控制 ...
- Java的IO系统
Java IO系统 "对语言设计人员来说,创建好的输入/输出系统是一项特别困难的任务." 由于存在大量不同的设计方案,所以该任务的困难性是很容易证明的.其中最大的 ...
- [转]PostgreSQL教程(十六):系统视图详解
这篇文章主要介绍了PostgreSQL教程(十六):系统视图详解,本文讲解了pg_tables.pg_indexes.pg_views.pg_user.pg_roles.pg_rules.pg_set ...
- 【Java基础系列】Java IO系统
前言 创建好的输入/输出系统不仅要考虑三种不同种类的IO系统(文件,控制台,网络连接)还需要通过大量不同的方式与他们通信(顺序,随机访问,二进制,字符,按行,按字等等). 一.输入和输出 Java的I ...
随机推荐
- Java与国际化
i18n(其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是"国际化"的简称. Java使用java.util.ResourceBu ...
- hdfs 查看报告--命令(hdfs dfsadmin -report)
[hadoop@master sbin]$ hdfs dfsadmin -reportConfigured Capacity: 8202977280 (7.64 GB)Present Capacity ...
- THUPC2019划水记
虽然早就打不动了,虽然一个队友提前说好跑路了,还是两个人来玩了玩.最大的失误是没有开场打模拟题,然后就没骗到钱,还是要向某一心骗钱不顾排名的队伍学习.这次的模拟题超简单,很愉快地就打完了,也没调多久, ...
- 人工智能实践:TensorFlow 框架
张量.计算图.会话 基本概念 基于Tensorflow的NN:用张量表示数据,用计算图搭建神经网络,用会话执行计算图,优化线上的权重(参数),得到模型. 张量(Tensor):张量就是多维数组(列表) ...
- CUDA 9.1/9.2 与 Visual Studio 2017 (VS2017 15.6.4) 的不兼容问题
2018年7月9日更新: CUDA已推出9.2版本,最高支持MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6). 然而最新版 ...
- Ajax学习(1)
Web 1.0 它指的就是具有完全不同的请求和响应模型的传统 Web.比如,到 hdu.edu.cn 网站上点击一个按钮.就会对服务器发送一个请求,然后响应再返回到浏览器.该请求不仅仅是新内容和项目列 ...
- 第一课、OpenGL绘制直线等等
第一课.OpenGL绘制直线等等 分类: [开发技术]OpenGL 2012-01-18 14:59 5217人阅读 评论(0) 收藏 举报 buffer图形c // // main.c // o ...
- JEECMS-新闻内容中遍历批量上传的图片
[#list content.pictures as p] <li value="${p_index+1}"> <img src="${p.imgPat ...
- [51nod] 1432 独木桥 贪心
n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...
- ue4 创建简易动画
这个功能本来是在原动画基础上做调整用的,所以直接用来做动画并不是很合适,如果要做复杂动画,叠加的轨迹会非常多,不好用 (蒙皮好的)模型右键,创建一个动画合成 点开这个动画合成,创建动画序列(就是普通动 ...