首页 > 其他 > 详细

网络IO-IO流的数据源

时间:2020-05-12 22:26:23      阅读:69      评论:0      收藏:0      [点我收藏+]

IO流的数据源

IO流的数据来源分别为四种硬盘、内存、键盘、网络

硬盘

public class TestDemo {
    public static void main(String[] args) {
        //磁盘IO
        try {
            FileInputStream fileInputStream =new FileInputStream("F:/test.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

内存

public class TestDemo02 {
    public static void main(String[] args) {
        //内存
        String str ="hello world";
        ByteArrayInputStream byteArrayInputStream =new ByteArrayInputStream(str.getBytes());
        int i = 0;
        while ((i = byteArrayInputStream.read()) != -1){
            System.out.print((char)i);
        }
    }
}

 

键盘

public class TestDemo03 {
    public static void main(String[] args) throws IOException {
        //键盘Scanner
        InputStream inputStream = System.in;
        int i = 0;
        while ((i = inputStream.read()) != -1){
            System.out.print((char)i);
        }
    }
}

 

网络

public class TestDemo04 {
    public static void main(String[] args) throws IOException {
        //网络IO
        Socket socket = new Socket();
        socket.getInputStream();
        socket.getOutputStream();
    }
}

网络IO-IO流的数据源

原文:https://www.cnblogs.com/liyaolog/p/12879135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!