六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

Java 小功能

[复制链接]

升级  32%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
16
 楼主| 发表于 2013-1-29 09:31:29 | 显示全部楼层 |阅读模式
1. 用checkbox实现单选功能
<SCRIPT type="text/javascript">function disable(){var len = document.getElementsByName("checkbox2").length;var count = 0;var studentid = 0;for (var i = 0; i < len; i++){         if (document.getElementsByName("checkbox2").checked == true)            {           count ++;            studentid =document.getElementsByName("checkbox2").value ;            }        }        if(count == 1)        {        window.location.href="attendance!disable.ptm?studentid="+studentid;        } else if(count>1)        {        alert("只能禁用单个学生资源");        } else        {        alert("请选择某个学生资源进行禁用操作");        }}</SCRIPT>

2. 纠正一个错误的认识:
如果页面有很多checkbox,我们需要传选中的checkbox的ids到action,只需要在action声明一个int类型的数组接受Id就行了。

3. copy多个文件夹下的跟中文件
public static void main(String[] args) throws IOException {File   fold   =   new File( "Z:\\"); File[] allFile = fold.listFiles();System.out.println(allFile.length);int ii=0;for (int i = 1; i <= allFile.length; i++) {System.out.println(allFile[i-   1].getAbsolutePath());    int folder = Integer.parseInt(allFile[i-1].getAbsolutePath().substring(3));File   tt   =   new File( "Z:\\"+folder+"\\"); File[] f = tt.listFiles();    if (f!=null && f.length>0 && f[0].isFile())    {       for (int j = 0; j < f.length; j++)    {       FileInputStream input = new FileInputStream(f[j]);                   FileOutputStream output = new FileOutputStream(  "Z:\\z23456\\" + (f[j].getName()).toString());                   byte[] b = new byte[1024 * 2040];                   int len;                   while ((len = input.read(b)) != -1) {                       output.write(b, 0, len);                   }                   output.flush();                   output.close();                   input.close();                   ii++;                System.out.println("copy第n个文件"+ii);}            }   }}

重命名很多文件
public static void main(String[] args) throws IOException {File   fold   =   new File( "D:\\test\\"); File[] allFile = fold.listFiles();for (int i = 1; i <= allFile.length; i++) {//System.out.println(allFile[i-1].getAbsolutePath());File   file   =   new File(allFile[i-1].getAbsolutePath());String name =  file.getName().substring(0,file.getName().indexOf("."))+"_建议书"+file.getName().substring(file.getName().indexOf("."), file.getName().length());if(file.exists()){file.renameTo(new File("D:\\test\\"+name));}System.out.println("重命名第"+i+"个文件");}System.out.println("重命名 完毕。。。");}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表