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); 11 System.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 public static 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输入输出流,还有文件流,过滤器。
以下附今日学习异常捕捉截图:
原文地址:https://www.cnblogs.com/sucker/p/10575617.html
时间: 2024-10-21 00:08:02