38.字节流InputStream和OutputStream的子类,以及对应的字符流有哪些 ------一二熊猫

字节流InputStream和OutputStream的大致子类如下:
在这里插入图片描述
在这里插入图片描述
java标准io输入/输出in,out:

//java标准io输入/输出

package io;

import java.io.IOException;

public class io_two {
	public static void main(String args[]) throws IOException
    { 
		
		System.out.print("input:");
		byte data[]=new byte[1024];
		int count=System.in.read(data);
		System.out.write(data);
		System.out.println();
		for(int i=0;i<count;i++)
		{
			System.out.print(" "+data[i]);
		}
		System.out.println();
		for(int j=0;j<count;j++)
		{
			System.out.print((char)data[j]);
		}
		
    }

}

文件读取,FileInputStream实例

package io;
import java.io.*;
public class io_one
	{
		
	    public static void main(String args[]) throws IOException
	    { 
	        try {
	        	FileInputStream ad=new FileInputStream("hello.txt");
	        	int n=512, c=0;
	        	byte []data=new byte[512];
	        	while((c=ad.read(data,0,n))!=-1);{
	        		System.out.print(new String(data,0,n));
	        	}
	        	System.out.println();
	        	ad.close();
	        }
	        catch(IOException ioe) {
	        	System.out.println(ioe);
	        }
	        catch(Exception io) {
	        	System.out.println(io);
	        }
		
	    }
	}

文件的写入,FileOutputStream例子

//写入文件

package io;
import java.io.*;
public class io_three {
	public static void main(String args[]) 
    {
		try {
			System.out.print("Input:");
			int count,n=1024;
			byte data[]=new byte[n];
			count=System.in.read(data);
			FileOutputStream ad =new FileOutputStream("make.txt");//写入make这个txt文本中
			ad.write(data,0,count);
			ad.close();
			System.out.print("Save to Writel.txt!");
			
		}
		catch(IOException ioe)
		{System.out.print(ioe);}
		catch(Exception io)
		{System.out.print(io);}
    }
	

}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值