UI

it2022-05-05  154

一、IO流的三种分类方式1.按流的方向分为:输入流和输出流2.按流的数据单位不同分为:字节流和字符流3.按流的功能不同分为:节点流和处理流二、IO流的四大抽象类:字符流:Reader Writer字节流:InputStream(读数据)OutputStream(写数据)三、InputStream的基本方法int read() throws IOException 读取一个字节以整数形式返回,如果返回-1已到输入流的末尾void close() throws IOException 关闭流释放内存资源long skip(long n) throws IOException 跳过n个字节不读四、OutputStream的基本方法void write(int b) throws IOException 向输出流写入一个字节数据void flush() throws IOException 将输出流中缓冲的数据全部写出到目的地五、Writer的基本方法void write(int c) throws IOException 向输出流写入一个字符数据void write(String str) throws IOException将一个字符串中的字符写入到输出流void write(String str,int offset,int length)将一个字符串从offset开始的length个字符写入到输出流void flush() throws IOException将输出流中缓冲的数据全部写出到目的地六、Reader的基本方法int read() throws IOException 读取一个字符以整数形式返回,如果返回-1已到输入流的末尾七、节点流类型八、访问文件之FileInputStream和FileOutputStream继承基类用于向文件中输入输出字节九、访问文件之FileReader和FileWriter继承基类用于向文件中输入输出字符----输出流在构造函数第二个参数可以设置true意义为跟在已有文件后进行输入----此类流会抛出FileNotFoundException需要对其进行显示捕捉十、缓冲流:缓冲流要套接在相应的节点流之上,提高了读写的效率。此处理流的构造方法都得传相对应的基类类型BufferedReader:提供了readLine方法用于高校读取一行字符串BufferedWriter:提供了newLine用于写入一个行分隔符也就是换行BufferedInputStream 没多大用处BufferedOutputStream 没多大用处十一、转换流:主要作用将字节流转换成字符流。用处较大!转换流在构造时可以指定其编码集合InputStreamReader需要和InputStream套接OutputStreamWriter需要和OutputStream套接例:OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream(文件路径);方法例:osw.getEncoding(); 获得流的编码方式十二、数据流与字节数组流:数据流主要为实现可以存取Java原始数据类型如long,boolean数据流是字节流DataInputStream需要和InputStream套接DataOutputStream需要和OutputStream套接DataInputStream方法:readBoolean() readInt() read……()……readUTF():网络传输常用方法 读一个Unicode字符串DataOutputStream方法与DataInputStream基本对应为写的方法//此构造函数等于已可以往一个字节数组里输入内容ByteArrayOutputStream baos = new ByteArrayOutputStream ();//此方法为获取一个字节数组方法返回字节数组baos.toByteArray();//此方法获取字节数组占了多少字节new ByteArrayInputStream(一个字节数组)。available()1ByteArrayOutputStream baos =2 new ByteArrayOutputStream();3 DataOutputStream dos =4 new DataOutputStream(baos);5 try {6 dos.writeDouble(Math.random());7 dos.writeBoolean(true);8 ByteArrayInputStream bais =9 new ByteArrayInputStream(baos.toByteArray());10 System.out.println(bais.available());11 DataInputStream dis = new DataInputStream(bais);12 System.out.println(dis.readDouble());13 System.out.println(dis.readBoolean());14 dos.close(); dis.close();15 } catch (IOException e) {16 e.printStackTrace();17 }十二、Print流Print流只有输出流无输入流,PrintWriter和PrintStream分别针对字符字节两个类提供了重载的Print和Println方法用于多种数据类型的输出PrintWriter和PrintStream的输出操作不会抛出异常PrintWriter和PrintStream有自动flush功能----System.setOut(接收OutputStream类):用于设置系统默认输出流十三、Object流等同于c#序列化,用直接将Object写入或读出transient关键字为不序列化此成员变量需要序列化的类必须实现Serializable接口主要方法:writeObject(Object); readObject();读出为Object类型需要强转数据类型

转载于:https://www.cnblogs.com/Bingley123/p/5463381.html

相关资源:android 漂亮的UI界面 完整的界面设计

最新回复(0)