编程练习生的第六天

IO总结
流: 流的作用,流的特点,流的功能,流的使用
节点流:最基本完成读入写出功能
字节流 : 万能流
FileInputStream | FileOutputStream -->文件操作
字节数组流(了解),字节节点流 不是操作文件,不是读入写出文件,而是读入字节数组中的内容,写出到字节数组
ByteArrayInputStream ByteArrayOutputStream
字符流 :纯文本
FileReader FileWriter
功能流(节点流):
缓冲流 : 提高节点流的功能和读写效率
字节缓冲流–没有新增方法
字符缓冲流–有新增方法,读取一行,插入换行符
转换流:字节->字符
InputStreamReader OutputStreamWriter
data流(字节节点流[文件|字节数组]):读写保留基本数据类型+字符串
DataInputStream DataOutputStream 新增方法:readXxx() writeXxx()
对象流(字节节点流[文件|字节数组]):读写对象类型信息
ObjectInputStream ObjectOutp

 public static void main(String[] args) throws IOException {
  File f = new File("E:/hehe.txt");
  
  InputStream  is = new FileInputStream(f);
  System.out.println(is.read());
 
  byte []b = new byte[is.available()];
  is.read(b);
  System.out.println(Arrays.toString(b));
  System.out.println(new String(b,0,is.available()));
 
  
 }
}

模拟定义容器类

class MyContainer{
 private String[] arr;  //存储容器数据的数组
 private int size;  //容器对象存储的数据个数
 
 public MyContainer() {
  arr=new String[0];
 }
 
 //根据索引修改
 
 //删除数据
 public void remove(int index) {
  if(index<0 || index>=size){
   throw new ArrayIndexOutOfBoundsException(index+"越界了亲~~~");
  }
  //备份原数组
  String[] temp=arr;
  arr=new String[size-1];
  //i代表原数组数据的索引
  for(int i=0;i<size;i++){
   if(i>=index){
    if(i==index){
     continue;
    }
    arr[i-1]=temp[i];
   }else{
    arr[i]=temp[i];
   }
  }
  size--;
 }
//获取方法 根据索引获取数据
 public String get(int index) {
  if(index<0 || index>=size){
   throw new ArrayIndexOutOfBoundsException(index+"越界了亲~~~");
  }
  return arr[index];
 }
 //添加功能
 public void add(String value) {
  //备份原数组
  String[] temp=arr;
  //arr指向新数组
  arr=new String[size+1];
  //数组的拷贝  i控制原数组和新数组的索引
  for(int i=0;i<size;i++){
   arr[i]=temp[i];
  }
  arr[size]=value;
  size++;
 }
 
 public int length(){
  return this.size;
 }
 
 @Override
 public String toString() {
  return "MyContainer [arr=" + Arrays.toString(arr) + ", size=" + size + "]";
 }
}

									2019.07.13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值