标签:input length 输出 tput 输入 stack string int try
*装饰模式处理流装饰字节流输入:
File f =new File("C:\\Users\\10853\\eclipse-workspace\\hell\\src\\hell\\abc");
InputStream is =null;
try {
**is=new BufferedInputStream(new FileInputStream(f));**
byte[] flush =new byte[1024];
int len=-1;
while((len=is.read(flush))!=-1)
{
is.read(flush,0,len);
}
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=is)
{
i**s.close();** //关闭处理流,会自动关闭字节流
}
}catch(IOException e)
{
e.printStackTrace();
}
}
处理流装饰字节流输出:
File f=new File("D:d/c.txt");
OutputStream os =null;
try
{
** os=new BufferedOutputStream(new FileOutputStream(f));**
String s="addaa";
byte[] datas=s.getBytes();
os.write(datas,0,datas.length);
os.flush();
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(**null!=os**) //关闭处理流会自动关闭字节流
{
os.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
标签:input length 输出 tput 输入 stack string int try
原文地址:https://blog.51cto.com/14437184/2423865