首页 > 编程语言 > 详细

2016.3.17(Java I/O系统)

时间:2016-03-18 00:10:59      阅读:297      评论:0      收藏:0      [点我收藏+]

操作 Java I/O输入输出流的基本步骤

1 创建管道
2 读写操作
3 关闭管道

输入流:

public class InputStreamTest {
public static void main(String[] args) {
//File
//String filePath
try {
InputStream in = new FileInputStream("file/test.txt");

// int i = 0;
//
// while(true){
// if((i = in.read()) != -1){
// System.out.println(i);
// }else{
// break;
// }
// }

int i = 0;
byte[] by = new byte[1024];
while(true){
if((i = in.read(by)) != -1){

}else{
break;
}
}

String info = new String(by);

String [] a = info.split("@");

System.out.println(a[0] + " " + a[1].trim());

in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}


输出流:

public static void main(String[] args) {
try {
OutputStream out = new FileOutputStream("file/test.txt", true);
String str = "zhangsan@123";

out.write(str.getBytes());

out.flush();//多一步刷新操作
out.close();
} catch (FileNotFoundException e) {

e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

2016.3.17(Java I/O系统)

原文:http://www.cnblogs.com/CMCM/p/5289953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!