国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IO流-字符流

2019-11-06 10:00:09
字體:
來源:轉載
供稿:網友

1:字符流(掌握) (1)字節流操作中文數據不是特別的方便,所以就出現了轉換流。 轉換流的作用就是把字節流轉換字符流來使用。 (2)轉換流其實是一個字符流 字符流 = 字節流 + 編碼表 (3)編碼表 A:就是由字符和對應的數值組成的一張表 B:常見的編碼表 ASCII ISO-8859-1 GB2312 GBK GB18030 UTF-8 C:字符串中的編碼問題 編碼 String – byte[] 解碼 byte[] – String (4)IO流中的編碼問題 A:OutputStreamWriter OutputStreamWriter(OutputStream os):默認編碼,GBK OutputStreamWriter(OutputStream os,String charsetName):指定編碼。

/* * OutputStreamWriter(OutputStream out):根據默認編碼把字節流的數據轉換為字符流 * OutputStreamWriter(OutputStream out,String charsetName):根據指定編碼把字節流數據轉換為字符流 * 把字節流轉換為字符流。 * 字符流 = 字節流 +編碼表。 */public class OutputStreamWriterDemo { public static void main(String[] args) throws IOException { // 創建對象 // OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream( // "osw.txt")); // 默認GBK // OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream( // "osw.txt"), "GBK"); // 指定GBK OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream( "osw.txt"), "UTF-8"); // 指定UTF-8 // 寫數據 osw.write("中國"); // 釋放資源 osw.close(); }} B:InputStreamReader InputStreamReader(InputStream is):默認編碼,GBK InputStreamReader(InputStream is,String charsetName):指定編碼/* * InputStreamReader(InputStream is):用默認的編碼讀取數據 * InputStreamReader(InputStream is,String charsetName):用指定的編碼讀取數據 */public class InputStreamReaderDemo { public static void main(String[] args) throws IOException { // 創建對象 // InputStreamReader isr = new InputStreamReader(new FileInputStream( // "osw.txt")); // InputStreamReader isr = new InputStreamReader(new FileInputStream( // "osw.txt"), "GBK"); InputStreamReader isr = new InputStreamReader(new FileInputStream( "osw.txt"), "UTF-8"); // 讀取數據 // 一次讀取一個字符 int ch = 0; while ((ch = isr.read()) != -1) { System.out.PRint((char) ch); } // 釋放資源 isr.close(); }} C:編碼問題其實很簡單 編碼只要一致即可(5)字符流 Reader |--InputStreamReader |--FileReader |--BufferedReader/* * InputStreamReader的方法: * int read():一次讀取一個字符 * int read(char[] chs):一次讀取一個字符數組 */public class InputStreamReaderDemo { public static void main(String[] args) throws IOException { // 創建對象 InputStreamReader isr = new InputStreamReader(new FileInputStream( "StringDemo.java")); // 一次讀取一個字符 // int ch = 0; // while ((ch = isr.read()) != -1) { // System.out.print((char) ch); // } // 一次讀取一個字符數組 char[] chs = new char[1024]; int len = 0; while ((len = isr.read(chs)) != -1) { System.out.print(new String(chs, 0, len)); } // 釋放資源 isr.close(); }}/* * BufferedReader * 從字符輸入流中讀取文本,緩沖各個字符,從而實現字符、數組和行的高效讀取。 * 可以指定緩沖區的大小,或者可使用默認的大小。大多數情況下,默認值就足夠大了。 * * BufferedReader(Reader in) */public class BufferedReaderDemo { public static void main(String[] args) throws IOException { // 創建字符緩沖輸入流對象 BufferedReader br = new BufferedReader(new FileReader("bw.txt")); // 方式1 // int ch = 0; // while ((ch = br.read()) != -1) { // System.out.print((char) ch); // } // 方式2 char[] chs = new char[1024]; int len = 0; while ((len = br.read(chs)) != -1) { System.out.print(new String(chs, 0, len)); } // 釋放資源 br.close(); }} Writer |--OutputStreamWriter |--FileWriter |--BufferedWriter/* * OutputStreamWriter的方法: * public void write(int c):寫一個字符 * public void write(char[] cbuf):寫一個字符數組 * public void write(char[] cbuf,int off,int len):寫一個字符數組的一部分 * public void write(String str):寫一個字符串 * public void write(String str,int off,int len):寫一個字符串的一部分 * * 面試題:close()和flush()的區別? * A:close()關閉流對象,但是先刷新一次緩沖區。關閉之后,流對象不可以繼續再使用了。 * B:flush()僅僅刷新緩沖區,刷新之后,流對象還可以繼續使用。 */public class OutputStreamWriterDemo { public static void main(String[] args) throws IOException { // 創建對象 OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream( "osw2.txt")); // 寫數據 // public void write(int c):寫一個字符 // osw.write('a'); // osw.write(97); // 為什么數據沒有進去呢? // 原因是:字符 = 2字節 // 文件中數據存儲的基本單位是字節。 // void flush() // public void write(char[] cbuf):寫一個字符數組 // char[] chs = {'a','b','c','d','e'}; // osw.write(chs); // public void write(char[] cbuf,int off,int len):寫一個字符數組的一部分 // osw.write(chs,1,3); // public void write(String str):寫一個字符串 // osw.write("我愛林青霞"); // public void write(String str,int off,int len):寫一個字符串的一部分 osw.write("我愛林青霞", 2, 3); // 刷新緩沖區 osw.flush(); // osw.write("我愛林青霞", 2, 3); // 釋放資源 osw.close(); // java.io.IOException: Stream closed // osw.write("我愛林青霞", 2, 3); }}/* * 字符流為了高效讀寫,也提供了對應的字符緩沖流。 * BufferedWriter:字符緩沖輸出流 * BufferedReader:字符緩沖輸入流 * * BufferedWriter:字符緩沖輸出流 * 將文本寫入字符輸出流,緩沖各個字符,從而提供單個字符、數組和字符串的高效寫入。 * 可以指定緩沖區的大小,或者接受默認的大小。在大多數情況下,默認值就足夠大了。 */public class BufferedWriterDemo { public static void main(String[] args) throws IOException { // BufferedWriter(Writer out) // BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( // new FileOutputStream("bw.txt"))); BufferedWriter bw = new BufferedWriter(new FileWriter("bw.txt")); bw.write("hello"); bw.write("world"); bw.write("java"); bw.flush(); bw.close(); }}(6)復制文本文件(5種方式)/* * 需求:把當前項目目錄下的a.txt內容復制到當前項目目錄下的b.txt中 * * 數據源: * a.txt -- 讀取數據 -- 字符轉換流 -- InputStreamReader -- FileReader -- BufferedReader * 目的地: * b.txt -- 寫出數據 -- 字符轉換流 -- OutputStreamWriter -- FileWriter -- BufferedWriter */public class CopyFileDemo { public static void main(String[] args) throws IOException { // 封裝數據源 BufferedReader br = new BufferedReader(new FileReader("a.txt")); // 封裝目的地 BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt")); // 兩種方式其中的一種一次讀寫一個字符數組 char[] chs = new char[1024]; int len = 0; while ((len = br.read(chs)) != -1) { bw.write(chs, 0, len); bw.flush(); } // 釋放資源 bw.close(); br.close(); }}/* * 需求:把當前項目目錄下的a.txt內容復制到當前項目目錄下的b.txt中 * * 數據源: * a.txt -- 讀取數據 -- 字符轉換流 -- InputStreamReader -- FileReader -- BufferedReader * 目的地: * b.txt -- 寫出數據 -- 字符轉換流 -- OutputStreamWriter -- FileWriter -- BufferedWriter */public class CopyFileDemo2 { public static void main(String[] args) throws IOException { // 封裝數據源 BufferedReader br = new BufferedReader(new FileReader("a.txt")); // 封裝目的地 BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt")); // 讀寫數據 String line = null; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); bw.flush(); } // 釋放資源 bw.close(); br.close(); }}

2:IO流小結(掌握) IO流 |–字節流 |–字節輸入流 InputStream int read():一次讀取一個字節 int read(byte[] bys):一次讀取一個字節數組

|--FileInputStream |--BufferedInputStream |--字節輸出流 OutputStream void write(int by):一次寫一個字節 void write(byte[] bys,int index,int len):一次寫一個字節數組的一部分 |--FileOutputStream |--BufferedOutputStream |--字符流 |--字符輸入流 Reader int read():一次讀取一個字符 int read(char[] chs):一次讀取一個字符數組 |--InputStreamReader |--FileReader |--BufferedReader String readLine():一次讀取一個字符串 |--字符輸出流 Writer void write(int ch):一次寫一個字符 void write(char[] chs,int index,int len):一次寫一個字符數組的一部分 |--OutputStreamWriter |--FileWriter |--BufferedWriter void newLine():寫一個換行符 void write(String line):一次寫一個字符串

3:案例(理解 練習一遍) A:復制文本文件 5種方式(掌握)

/* * 復制文本文件 * * 分析: * 復制數據,如果我們知道用記事本打開并能夠讀懂,就用字符流,否則用字節流。 * 通過該原理,我們知道我們應該采用字符流更方便一些。 * 而字符流有5種方式,所以做這個題目我們有5種方式。推薦掌握第5種。 * 數據源: * c://a.txt -- FileReader -- BufferdReader * 目的地: * d://b.txt -- FileWriter -- BufferedWriter */public class CopyFileDemo { public static void main(String[] args) throws IOException { String srcString = "c://a.txt"; String destString = "d://b.txt"; // method1(srcString, destString); // method2(srcString, destString); // method3(srcString, destString); // method4(srcString, destString); method5(srcString, destString); } // 字符緩沖流一次讀寫一個字符串 private static void method5(String srcString, String destString) throws IOException { BufferedReader br = new BufferedReader(new FileReader(srcString)); BufferedWriter bw = new BufferedWriter(new FileWriter(destString)); String line = null; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); bw.flush(); } bw.close(); br.close(); } // 字符緩沖流一次讀寫一個字符數組 private static void method4(String srcString, String destString) throws IOException { BufferedReader br = new BufferedReader(new FileReader(srcString)); BufferedWriter bw = new BufferedWriter(new FileWriter(destString)); char[] chs = new char[1024]; int len = 0; while ((len = br.read(chs)) != -1) { bw.write(chs, 0, len); } bw.close(); br.close(); } // 字符緩沖流一次讀寫一個字符 private static void method3(String srcString, String destString) throws IOException { BufferedReader br = new BufferedReader(new FileReader(srcString)); BufferedWriter bw = new BufferedWriter(new FileWriter(destString)); int ch = 0; while ((ch = br.read()) != -1) { bw.write(ch); } bw.close(); br.close(); } // 基本字符流一次讀寫一個字符數組 private static void method2(String srcString, String destString) throws IOException { FileReader fr = new FileReader(srcString); FileWriter fw = new FileWriter(destString); char[] chs = new char[1024]; int len = 0; while ((len = fr.read(chs)) != -1) { fw.write(chs, 0, len); } fw.close(); fr.close(); } // 基本字符流一次讀寫一個字符 private static void method1(String srcString, String destString) throws IOException { FileReader fr = new FileReader(srcString); FileWriter fw = new FileWriter(destString); int ch = 0; while ((ch = fr.read()) != -1) { fw.write(ch); } fw.close(); fr.close(); }}B:復制圖片(二進制流數據) 4種方式(掌握)/* * 復制圖片 * * 分析: * 復制數據,如果我們知道用記事本打開并能夠讀懂,就用字符流,否則用字節流。 * 通過該原理,我們知道我們應該采用字節流。 * 而字節流有4種方式,所以做這個題目我們有4種方式。推薦掌握第4種。 * * 數據源: * c://a.jpg -- FileInputStream -- BufferedInputStream * 目的地: * d://b.jpg -- FileOutputStream -- BufferedOutputStream */public class CopyImageDemo { public static void main(String[] args) throws IOException { // 使用字符串作為路徑 // String srcString = "c://a.jpg"; // String destString = "d://b.jpg"; // 使用File對象做為參數 File srcFile = new File("c://a.jpg"); File destFile = new File("d://b.jpg"); // method1(srcFile, destFile); // method2(srcFile, destFile); // method3(srcFile, destFile); method4(srcFile, destFile); } // 字節緩沖流一次讀寫一個字節數組 private static void method4(File srcFile, File destFile) throws IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream( srcFile)); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(destFile)); byte[] bys = new byte[1024]; int len = 0; while ((len = bis.read(bys)) != -1) { bos.write(bys, 0, len); } bos.close(); bis.close(); } // 字節緩沖流一次讀寫一個字節 private static void method3(File srcFile, File destFile) throws IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream( srcFile)); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(destFile)); int by = 0; while ((by = bis.read()) != -1) { bos.write(by); } bos.close(); bis.close(); } // 基本字節流一次讀寫一個字節數組 private static void method2(File srcFile, File destFile) throws IOException { FileInputStream fis = new FileInputStream(srcFile); FileOutputStream fos = new FileOutputStream(destFile); byte[] bys = new byte[1024]; int len = 0; while ((len = fis.read(bys)) != -1) { fos.write(bys, 0, len); } fos.close(); fis.close(); } // 基本字節流一次讀寫一個字節 private static void method1(File srcFile, File destFile) throws IOException { FileInputStream fis = new FileInputStream(srcFile); FileOutputStream fos = new FileOutputStream(destFile); int by = 0; while ((by = fis.read()) != -1) { fos.write(by); } fos.close(); fis.close(); }}C:把集合中的數據存儲到文本文件/* * 需求:把ArrayList集合中的字符串數據存儲到文本文件 * * 分析: * 通過題目的意思我們可以知道如下的一些內容, * ArrayList集合里存儲的是字符串。 * 遍歷ArrayList集合,把數據獲取到。 * 然后存儲到文本文件中。 * 文本文件說明使用字符流。 * * 數據源: * ArrayList<String> -- 遍歷得到每一個字符串數據 * 目的地: * a.txt -- FileWriter -- BufferedWriter */public class ArrayListToFileDemo { public static void main(String[] args) throws IOException { // 封裝數據與(創建集合對象) ArrayList<String> array = new ArrayList<String>(); array.add("hello"); array.add("world"); array.add("java"); // 封裝目的地 BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt")); // 遍歷集合 for (String s : array) { // 寫數據 bw.write(s); bw.newLine(); bw.flush(); } // 釋放資源 bw.close(); }}D:把文本文件中的數據讀取到集合并遍歷集合/* * 需求:從文本文件中讀取數據(每一行為一個字符串數據)到集合中,并遍歷集合 * * 分析: * 通過題目的意思我們可以知道如下的一些內容, * 數據源是一個文本文件。 * 目的地是一個集合。 * 而且元素是字符串。 * * 數據源: * b.txt -- FileReader -- BufferedReader * 目的地: * ArrayList<String> */public class FileToArrayListDemo { public static void main(String[] args) throws IOException { // 封裝數據源 BufferedReader br = new BufferedReader(new FileReader("b.txt")); // 封裝目的地(創建集合對象) ArrayList<String> array = new ArrayList<String>(); // 讀取數據存儲到集合中 String line = null; while ((line = br.readLine()) != null) { array.add(line); } // 釋放資源 br.close(); // 遍歷集合 for (String s : array) { System.out.println(s); } }}E:復制單級文件夾F:復制單級文件夾中指定的文件并修改名稱 回顧一下批量修改名稱/* * 需求:復制單級文件夾 * * 數據源:e://demo * 目的地:e://test * * 分析: * A:封裝目錄 * B:獲取該目錄下的所有文本的File數組 * C:遍歷該File數組,得到每一個File對象 * D:把該File進行復制 */public class CopyFolderDemo { public static void main(String[] args) throws IOException { // 封裝目錄 File srcFolder = new File("e://demo"); // 封裝目的地 File destFolder = new File("e://test"); // 如果目的地文件夾不存在,就創建 if (!destFolder.exists()) { destFolder.mkdir(); } // 獲取該目錄下的所有文本的File數組 File[] fileArray = srcFolder.listFiles(); // 遍歷該File數組,得到每一個File對象 for (File file : fileArray) { // System.out.println(file); // 數據源:e://demo//e.mp3 // 目的地:e://test//e.mp3 String name = file.getName(); // e.mp3 File newFile = new File(destFolder, name); // e://test//e.mp3 copyFile(file, newFile); } } private static void copyFile(File file, File newFile) throws IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream( file)); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(newFile)); byte[] bys = new byte[1024]; int len = 0; while ((len = bis.read(bys)) != -1) { bos.write(bys, 0, len); } bos.close(); bis.close(); }}G:復制多級文件夾/* * 需求:復制多極文件夾 * * 數據源:E:/JavaSE/day21/code/demos * 目的地:E:// * * 分析: * A:封裝數據源File * B:封裝目的地File * C:判斷該File是文件夾還是文件 * a:是文件夾 * 就在目的地目錄下創建該文件夾 * 獲取該File對象下的所有文件或者文件夾File對象 * 遍歷得到每一個File對象 * 回到C * b:是文件 * 就復制(字節流) */public class CopyFoldersDemo { public static void main(String[] args) throws IOException { // 封裝數據源File File srcFile = new File("E://JavaSE//day21//code//demos"); // 封裝目的地File File destFile = new File("E://"); // 復制文件夾的功能 copyFolder(srcFile, destFile); } private static void copyFolder(File srcFile, File destFile) throws IOException { // 判斷該File是文件夾還是文件 if (srcFile.isDirectory()) { // 文件夾 File newFolder = new File(destFile, srcFile.getName()); newFolder.mkdir(); // 獲取該File對象下的所有文件或者文件夾File對象 File[] fileArray = srcFile.listFiles(); for (File file : fileArray) { copyFolder(file, newFolder); } } else { // 文件 File newFile = new File(destFile, srcFile.getName()); copyFile(srcFile, newFile); } } private static void copyFile(File srcFile, File newFile) throws IOException { BufferedInputStream bis = new BufferedInputStream(new FileInputStream( srcFile)); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(newFile)); byte[] bys = new byte[1024]; int len = 0; while ((len = bis.read(bys)) != -1) { bos.write(bys, 0, len); } bos.close(); bis.close(); }}H:鍵盤錄入學生信息按照總分從高到低存儲到文本文件/* * 鍵盤錄入5個學生信息(姓名,語文成績,數學成績,英語成績),按照總分從高到低存入文本文件 * * 分析: * A:創建學生類 * B:創建集合對象 * TreeSet<Student> * C:鍵盤錄入學生信息存儲到集合 * D:遍歷集合,把數據寫到文本文件 */public class StudentDemo { public static void main(String[] args) throws IOException { // 創建集合對象 TreeSet<Student> ts = new TreeSet<Student>(new Comparator<Student>() { @Override public int compare(Student s1, Student s2) { int num = s2.getSum() - s1.getSum(); int num2 = num == 0 ? s1.getChinese() - s2.getChinese() : num; int num3 = num2 == 0 ? s1.getMath() - s2.getMath() : num2; int num4 = num3 == 0 ? s1.getEnglish() - s2.getEnglish() : num3; int num5 = num4 == 0 ? s1.getName().compareTo(s2.getName()) : num4; return num5; } }); // 鍵盤錄入學生信息存儲到集合 for (int x = 1; x <= 5; x++) { Scanner sc = new Scanner(System.in); System.out.println("請錄入第" + x + "個的學習信息"); System.out.println("姓名:"); String name = sc.nextLine(); System.out.println("語文成績:"); int chinese = sc.nextInt(); System.out.println("數學成績:"); int math = sc.nextInt(); System.out.println("英語成績:"); int english = sc.nextInt(); // 創建學生對象 Student s = new Student(); s.setName(name); s.setChinese(chinese); s.setMath(math); s.setEnglish(english); // 把學生信息添加到集合 ts.add(s); } // 遍歷集合,把數據寫到文本文件 BufferedWriter bw = new BufferedWriter(new FileWriter("students.txt")); bw.write("學生信息如下:"); bw.newLine(); bw.flush(); bw.write("姓名,語文成績,數學成績,英語成績"); bw.newLine(); bw.flush(); for (Student s : ts) { StringBuilder sb = new StringBuilder(); sb.append(s.getName()).append(",").append(s.getChinese()) .append(",").append(s.getMath()).append(",") .append(s.getEnglish()); bw.write(sb.toString()); bw.newLine(); bw.flush(); } // 釋放資源 bw.close(); System.out.println("學習信息存儲完畢"); }}I:把某個文件中的字符串排序后輸出到另一個文本文件中/* * 已知s.txt文件中有這樣的一個字符串:“hcexfgijkamdnoqrzstuvwybpl” * 請編寫程序讀取數據內容,把數據排序后寫入ss.txt中。 * * 分析: * A:把s.txt這個文件給做出來 * B:讀取該文件的內容,存儲到一個字符串中 * C:把字符串轉換為字符數組 * D:對字符數組進行排序 * E:把排序后的字符數組轉換為字符串 * F:把字符串再次寫入ss.txt中 */public class StringDemo { public static void main(String[] args) throws IOException { // 讀取該文件的內容,存儲到一個字符串中 BufferedReader br = new BufferedReader(new FileReader("s.txt")); String line = br.readLine(); br.close(); // 把字符串轉換為字符數組 char[] chs = line.toCharArray(); // 對字符數組進行排序 Arrays.sort(chs); // 把排序后的字符數組轉換為字符串 String s = new String(chs); // 把字符串再次寫入ss.txt中 BufferedWriter bw = new BufferedWriter(new FileWriter("ss.txt")); bw.write(s); bw.newLine(); bw.flush(); bw.close(); }}J:用Reader模擬BufferedReader的特有功能/* * 用Reader模擬BufferedReader的readLine()功能 * * readLine():一次讀取一行,根據換行符判斷是否結束,只返回內容,不返回換行符 */public class MyBufferedReader { private Reader r; public MyBufferedReader(Reader r) { this.r = r; } /* * 思考:寫一個方法,返回值是一個字符串。 */ public String readLine() throws IOException { /* * 我要返回一個字符串,我該怎么辦呢? 我們必須去看看r對象能夠讀取什么東西呢? 兩個讀取方法,一次讀取一個字符或者一次讀取一個字符數組 * 那么,我們要返回一個字符串,用哪個方法比較好呢? 我們很容易想到字符數組比較好,但是問題來了,就是這個數組的長度是多長呢? * 根本就沒有辦法定義數組的長度,你定義多長都不合適。 所以,只能選擇一次讀取一個字符。 * 但是呢,這種方式的時候,我們再讀取下一個字符的時候,上一個字符就丟失了 所以,我們又應該定義一個臨時存儲空間把讀取過的字符給存儲起來。 * 這個用誰比較和是呢?數組,集合,字符串緩沖區三個可供選擇。 * 經過簡單的分析,最終選擇使用字符串緩沖區對象。并且使用的是StringBuilder */ StringBuilder sb = new StringBuilder(); // 做這個讀取最麻煩的是判斷結束,但是在結束之前應該是一直讀取,直到-1 /* hello world java 104101108108111 119111114108100 1069711897 */ int ch = 0; while ((ch = r.read()) != -1) { //104,101,108,108,111 if (ch == '/r') { continue; } if (ch == '/n') { return sb.toString(); //hello } else { sb.append((char)ch); //hello } } // 為了防止數據丟失,判斷sb的長度不能大于0 if (sb.length() > 0) { return sb.toString(); } return null; } /* * 先寫一個關閉方法 */ public void close() throws IOException { this.r.close(); }}/* * 測試MyBufferedReader的時候,你就把它當作BufferedReader一樣的使用 */public class MyBufferedReaderDemo { public static void main(String[] args) throws IOException { MyBufferedReader mbr = new MyBufferedReader(new FileReader("my.txt")); String line = null; while ((line = mbr.readLine()) != null) { System.out.println(line); } mbr.close(); // System.out.println('/r' + 0); // 13 // System.out.println('/n' + 0);// 10 }}K:模擬LineNumberReader的特有功能
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 勐海县| 苏州市| 信丰县| 紫金县| 四平市| 镇康县| 双辽市| 洛阳市| 肃南| 象山县| 林州市| 崇仁县| 乌兰县| 浦江县| 麻城市| 巧家县| 蛟河市| 饶河县| 和平区| 庆云县| 津市市| 海淀区| 天祝| 仪征市| 茂名市| 仙游县| 崇州市| 博乐市| 南阳市| 林口县| 横山县| 大悟县| 叙永县| 中江县| 弥勒县| 东辽县| 蚌埠市| 东海县| 肇源县| 宁远县| 康乐县|