- import java.io.IOException;
- public class IOTest {
- public static void main(String[] args) {
- byte[] buffer = new byte[1024];
- try
- {
- int len = System.in.read(buffer);
- String s = new String(buffer , 0 , len);
- System.out.println("接收到了:"+len+"个字节");
- System.out.println(s);
- System.out.println("字符串长度为:"+s.length());
- }catch(IOException e)
- {
- }
- }
- }
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class IOTest1 {
- public static void main(String[] args) {
- byte[] buffer = new byte[1024];
- try {
- DataOutputStream out = new DataOutputStream(
- new BufferedOutputStream(
- new FileOutputStream("a.dat")));
- int i = 0xface;
- out.writeInt(i);
- out.close();
- DataInputStream in = new DataInputStream(
- new BufferedInputStream(
- new FileInputStream("a.dat")));
- int j = in.readInt();
- System.out.println(j);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
以上是今天学习的 io 输入输出流, 还有文件流, 过滤器.
以下附今日学习异常捕捉截图:
来源: http://www.bubuko.com/infodetail-2995507.html