zoukankan      html  css  js  c++  java
  • Java IO流

    import java.io.*;
    public class TRYIN1224 {
    public static void main(String[] args) throws Exception {
    //InputStream in  = new InputStream(System.in);//当然不可以呀宝贝 inputstream是一个抽象类无法实例化的 只能用它的子类呀 参数是向下转型啦
     File f1 = new File("a.txt");
     FileInputStream in = new FileInputStream("D:\211\child-5000.dat");
     System.out.println(loadStream(in)); //输入流是文件
    
    //        byte[] b = new byte[10];
    //        int count = 0;//局部变量必须自动初始化
    //        System.out.println("请输入字节数组:");
    //        count = System.in.read(b);//键盘输入的都存在数组b里
    //        ByteArrayInputStream in = new ByteArrayInputStream(b);
    //        System.out.println(loadStream(in));
    //String mes = "你好,world" ;
    //byte[] b = mes.getBytes() ;
    
    }
     public static String loadStream(InputStream in)throws Exception{
        String returns = null;
        DataInputStream changein = new DataInputStream(new BufferedInputStream(in));
        returns = changein.readUTF();
        return returns;
      }
    }
    import java.io.*;
    public class TRYIN1224{
        public static void main(String[] args) throws IOException {
            String s1= "hello world";
            byte[] b1= s1.getBytes();//!!!byte
            ByteArrayInputStream in = new ByteArrayInputStream(b1);//得到字节输入流啦!!!
            
            ByteArrayOutputStream out = new ByteArrayOutputStream(); //这里可以为空
            //System.out.println("将所有小写字母换成大写字母:"); //并写入字节数组输出流
            int len = 0;
            while((len = in.read()) != -1){  
            //read () 方法,这个方法 从输入流中读取数据的下一个字节。返回 0 到 255 范围内的 int 字节值
                char ch = (char)len;//int转char
                out.write(Character.toUpperCase(ch));//将大写字母内容写入out里  to Upper Case如果你想转char那就得这么转 加Character/区别字符串
                
            }
            System.out.println("再转为字符串:"+out.toString()); //得到输出流之后 这么转就行 输出流是配write 但是我现在只是想看看啊
            
        }
    }
  • 相关阅读:
    idea 中的new file 没有jsp
    springboot-helloworld-idea
    springboot-RequestMappingHandlerMapping
    swagger-注解
    springboot-mybatis
    js-dialog
    js-jsTree
    maven-tomct插件
    maven-插件地址
    docker入门 基础命令 docker安装
  • 原文地址:https://www.cnblogs.com/yundong333/p/12090178.html
Copyright © 2011-2022 走看看