Java 小功能
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.getAbsolutePath()); int folder = Integer.parseInt(allFile.getAbsolutePath().substring(3));File tt = new File( "Z:\\"+folder+"\\"); File[] f = tt.listFiles(); if (f!=null && f.length>0 && f.isFile()) { for (int j = 0; j < f.length; j++) { FileInputStream input = new FileInputStream(f); FileOutputStream output = new FileOutputStream("Z:\\z23456\\" + (f.getName()).toString()); byte[] b = new byte; 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.getAbsolutePath());File file = new File(allFile.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("重命名 完毕。。。");}
页:
[1]