带后台的html网站源码,网络推广公司方案,wordpress首页登陆,东莞网站建设方案表第五章#xff1a;IO流 #xff08;java.io包中#xff09; 三、字符流 1. 字符流的父类(抽象类)#xff1a; Reader#xff1a;字符输入流 对应的操作为读操作 功能方法#xff1a;read方法 Writer:字符输出流 对应的操作为写操作 功能方法#xff1a;write方法 … 第五章IO流 java.io包中 三、字符流 1. 字符流的父类(抽象类) Reader字符输入流 对应的操作为读操作 功能方法read方法 Writer:字符输出流 对应的操作为写操作 功能方法write方法 2. 文件字符流 (1) FileWriter文件字符输出流继承Writer中的方法 public void write(int n):将单个字符写入到文件中 (2) FileReader文件字符输入流继承Reader中的方法 public int read():一次读取一个字符的内容 3. 字符过滤流 (1) BufferedReader 功能方法readLine()一次性读取一行内容返回内容为String读取达到尾部返回-1 (2) PrintWriter println(参数); 4. 桥转换流 InputStreamReader/OutputStreamWriter:桥转换流设置 编解码格式 package testio2; import java.io.*; // 桥转换流: ctrA - ctrx - 设置格式 - ctrv -ctrs public class TestInputStreamReader { public static void main(String[] args) throws IOException { // 1. 创建文件字节输入流对象 FileInputStream fis new FileInputStream(file/k.txt); // 2. 创建桥转换流对象设置编解码格式 InputStreamReader isr new InputStreamReader(fis,GBK); // 3. 创建过滤流 BufferedReader br new BufferedReader(isr); // 4. 读操作 while(true){ String n br.readLine(); if(nnull) break; System.out.println(n); } // 5. 关闭流 br.close(); } } package testio2; import java.io.*; // 桥转换流: ctrA - ctrx - 设置格式 - ctrv -ctrs public class TestOutputStreamWriter { public static void main(String[] args) { PrintWriter pw null; try { FileOutputStream fos new FileOutputStream(file/my.txt); OutputStreamWriter osw new OutputStreamWriter(fos, GBK); pw new PrintWriter(osw); pw.println(嘻嘻); pw.println(哈哈); pw.print(呵呵); }catch (IOException e){ e.printStackTrace(); }finally { if(pw !null) { pw.close(); } } } } 四、File类 1. IO流对文件中的内容进行操作。 File类对文件自身进行操作例如删除文件文件重新命 名等。 2. 操作 public class TestFile { public static void main(String[] args) throws IOException { File file new File(file/hh.txt); /*System.out.println(file.exists()); file.createNewFile();*/ if(file.exists()){ System.out.println(文件存在则直接使用...); FileInputStream fis new FileInputStream(file); }else{ System.out.println(文件不存在创建新的文件....); file.createNewFile(); } } }