java_io_字符缓冲流的输入、输出-创新互联
新增方法:
输入:
BufferedReader breader=new BufferedReader(Reader reader);
.readLine()读取一行内容,返回字符串
输出:
BufferedWriter bwriter=new BufferedWirter(Writer writer);
.newLine() 写入一个换行符
输入:
File f =new File("C:\Users\10853\eclipse-workspace\hell\src\hell\abc");
BufferedReader reader=null;
try {
reader=new BufferedReader(new FileReader(f));
String line=null;
while((line=reader.readLine())!=null)//要添上!=null,不像c语言赋值表达式整个也有个真假结果
{
System.out.println(line);
}
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=reader)
{
reader.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
输出:
File f=new File("D:d/c.txt");
BufferedWriter bwriter=null;
try
{
bwriter=new BufferedWriter(new FileWriter(f));
String s="addad";
bwriter.write(s);
bwriter.newLine();
bwriter.append("aaaff");
bwriter.flush();
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=bwriter)
{
bwriter.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
本文标题:java_io_字符缓冲流的输入、输出-创新互联
网页地址:http://ybzwz.com/article/dgogho.html