下面的例子读出文件aa.txt,并将读出的内容中的小写字母a全部替换为大写字母A。import java.io.*;
public class IOTest
{ public static void main(String args[])
{try{ FileInputStream in=new FileInputStream("aa.txt") ;
PushbackInputStream push=new PushbackInputStream(in);
int c=0;
byte b[]=new byte[1];
while ( (c=push.read())!=-1)
{ if(c=='a') //回压的条件
{ push.unread('A'); //push回压字节'A'。
push.read(b,0,1); //push读出被回压的字节,放入数组b。
System.out.print(new String(b,0,1));
}
else
{System.out.print((char)c);
}
}
push.close();
}
catch(IOException e){}
}
}
public class IOTest
{ public static void main(String args[])
{try{ FileInputStream in=new FileInputStream("aa.txt") ;
PushbackInputStream push=new PushbackInputStream(in);
int c=0;
byte b[]=new byte[1];
while ( (c=push.read())!=-1)
{ if(c=='a') //回压的条件
{ push.unread('A'); //push回压字节'A'。
push.read(b,0,1); //push读出被回压的字节,放入数组b。
System.out.print(new String(b,0,1));
}
else
{System.out.print((char)c);
}
}
push.close();
}
catch(IOException e){}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货