0
点赞
收藏
分享

微信扫一扫

简单了解流


 

/*
*作者:呆萌老师
*☑csdn认证讲师
*☑51cto高级讲师
*☑腾讯课堂认证讲师
*☑网易云课堂认证讲师
*☑华为开发者学堂认证讲师
*☑爱奇艺千人名师计划成员
*在这里给大家分享技术、知识和生活
*各种干货,记得关注哦!
*/

简单了解流_数据

1、流的定义

        流是数据传输的载体的运行过程。且流具有指向性与映射性。流的底层建模的模型为管道模型,因此我们又称之为管道通信。流的设计模式为装饰者模式,大多数流的操作仅仅返回流的本体,因此我们又称之为管道内衬。

2、流的分类

        流根据数据类型分可分为字符流与字节流。根据数据操作来分类可分为文件、缓存、管道、基本数据类型、打印、对象(序列化与反序列化)。

3、流的目的

        流的目的是为了解决异件间的数据传输。

4、流的特性

        1、流是一个载体。其目的是为了解决数据传输的。

        2、流具有方向性。根据操作的不同(写入/读取)可分为输入流与输出流。

        3、流具有流动性(传输性)。流作为数据传输的载体本身具有传输性,否则将无法担任数据传输这个任务。

        4、序列化与反序列化,

5、知识拓展

        数据在计算机当中以文件的形式存在。因此我们对数据的操作实际上就是在对文件进行操作。

        ’代码实现

对文件操作

package com.Text;
import java.io.*;
public class Text {

public static void main(String[] args) {

File file = new File("E:\\a.txt");

if(!file.exists())

{

try {

file.createNewFile();

System.out.println("文件创建成功");

} catch (IOException e) {

e.printStackTrace();

}

} try {

FileOutputStream fileOutputStream = new FileOutputStream(file);

fileOutputStream.write("hello word".getBytes());

System.out.println(" 写入成功...");
FileInputStream fileInputStream = new FileInputStream(file);

int i=0;

byte[] bytes = new byte[1024];

while((i=fileInputStream.read(bytes))!=-1)

{

System.out.println(new String(bytes,0,i));

} fileInputStream.close();

fileOutputStream.close();

// file.delete(); } catch (Exception e) {

e.printStackTrace();

} }

}

  更多关注

​​https://edu.51cto.com/course/20124.html​​


举报

相关推荐

0 条评论