免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2071 | 回复: 1
打印 上一主题 下一主题

有谁知道这两段JAVA程序实现什么功能吗/?急 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-10 16:57 |只看该作者 |倒序浏览
这两段是分开的. 这两段JAVA程序分别实现什么功能?
第一段:
import java.io.*;
public class FileList
{ public static void main(String args[]) throws Exception
  { File file=new File("C:\\Windows");
    String[] fileList=file.list(new Filter("sy"));
    if(fileList.length!=0)
     for(int i=0;i<fileList.length;i++)
      System.out.println(fileList);
      else
      System.out.println("The fileList is null!");
  }
}
   class Filter implements FilenameFilter
  { String filterString;
    Filter(String filterString)
    { this.filterString=filterString;}
    public boolean accept(File file,String name)
    { return (name.toLowerCase().lastIndexOf(filterString.toLowerCase())!=-1);}
  }

第二段:
import java.io.*;
public class BufferedOutput{
  private static void printByteArray(byte[] b){
     if(b.length>0){
      String res="";
      for(int i=0;i<b.length-1;i++) res+=b+",";
       res+=b[b.length-1];
       System.out.println(res);
                   }
                                               }
public static void main(String[] args){
   try{
       ByteArrayOutputStream bufferout=new ByteArrayOutputStream();
       BufferedOutputStream out=new BufferedOutputStream(bufferout);
       out.write(0);
       out.flush();
       System.out.print("写入0并刷新缓冲区:");
       printByteArray(bufferout.toByteArray());
       byte[] b={1,2,3,4,5};
       out.write(b);
       System.out.print("写入数组b.不刷新缓冲区:");
       printByteArray(bufferout.toByteArray());
       out.write(b,2,3);
       out.flush();
       System.out.print("写入数组b部分数据.不刷新缓冲区:");
       printByteArray(bufferout.toByteArray());
       }
       catch(IOException e){
         e.printStackTrace();
                            }
}
}

论坛徽章:
0
2 [报告]
发表于 2008-02-12 10:41 |只看该作者
第一个类实现功能类似于“dir c:\windows\*sy*”
第二个类是测试BufferedOutputStream 的flush功能
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP