學習打卡第二天
阿新 • • 發佈:2019-03-22
lose args string sta tput generate mage 輸出流 dex
1 import java.io.IOException; 2 3 public class IOTest { 4 5 public static void main(String[] args) { 6 byte[] buffer = new byte[1024]; 7 try 8 { 9 int len = System.in.read(buffer); 10 String s = new String(buffer , 0 , len); 11System.out.println("接收到了:"+len+"個字節"); 12 System.out.println(s); 13 System.out.println("字符串長度為:"+s.length()); 14 }catch(IOException e) 15 { 16 17 } 18 19 20 } 21 22 }
1 import java.io.BufferedInputStream;2 import java.io.BufferedOutputStream; 3 import java.io.DataInputStream; 4 import java.io.DataOutputStream; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 7 import java.io.FileOutputStream; 8 import java.io.IOException; 9 10 public class IOTest1 { 11 12 publicstatic void main(String[] args) { 13 byte[] buffer = new byte[1024]; 14 try { 15 DataOutputStream out = new DataOutputStream( 16 new BufferedOutputStream( 17 new FileOutputStream("a.dat"))); 18 int i = 0xface; 19 out.writeInt(i); 20 out.close(); 21 DataInputStream in = new DataInputStream( 22 new BufferedInputStream( 23 new FileInputStream("a.dat"))); 24 int j = in.readInt(); 25 System.out.println(j); 26 } catch (FileNotFoundException e) { 27 // TODO Auto-generated catch block 28 e.printStackTrace(); 29 } catch (IOException e) 30 { 31 // TODO Auto-generated catch block 32 e.printStackTrace(); 33 } 34 35 } 36 37 }
以上是今天學習的io輸入輸出流,還有文件流,過濾器。
以下附今日學習異常捕捉截圖:
學習打卡第二天