`
业精于勤
  • 浏览: 4024 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

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")[i].checked == true)
            {
        	   count ++; 
        	   studentid =document.getElementsByName("checkbox2")[i].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("重命名 完毕。。。");
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics