记录一下最近项目中遇见的问题

File类的file.delete()不能删除文件

使用File类的delete删除文件时,要注意是否有流在使用改文件,请先关闭流再删除文件,否则删除不了

File copyFile = new File(file);
		File storePath = new File(path);
		if (!storePath.exists()) {
			storePath.mkdirs();
		}
		File newFile = new File(path,fileName);
		InputStream input = null;
		OutputStream output = null;
		try {
			input = new FileInputStream(copyFile);
			output = new FileOutputStream(newFile);
			byte[] buf = new byte[1024];
			int bytesRead;
			while ((bytesRead = input.read(buf)) != -1) {
				output.write(buf, 0, bytesRead);
			}
			copyFile.delete();//这句在删除,但是删除不了
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (input != null) {
				input.close();
			}
			if (output != null) {
				output.close();
			}
			
		}

修正后的代码

File copyFile = new File(file);
		File storePath = new File(path);
		if (!storePath.exists()) {
			storePath.mkdirs();
		}
		File newFile = new File(path,fileName);
		InputStream input = null;
		OutputStream output = null;
		try {
			input = new FileInputStream(copyFile);
			output = new FileOutputStream(newFile);
			byte[] buf = new byte[1024];
			int bytesRead;
			while ((bytesRead = input.read(buf)) != -1) {
				output.write(buf, 0, bytesRead);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (input != null) {
				input.close();
			}
			if (output != null) {
				output.close();
			}
			copyFile.delete();//可以正常删除
		}

前端css的问题

使用document.execCommand(‘copy’);隐藏生成的input后,就不能复制到剪切板了,解决办法,将生成的input放入一个div中在隐藏此div(主要是因为复制成功后在前端会生成一个input影响使用)

	var wbUrl =“复制我”;
	var input = document.createElement('input');
	$("copyId").setStyle("display","");
    document.getElementById("copyId").appendChild(input);
    input.setAttribute('value', wbUrl);
    input.select();
    if (document.execCommand('copy')) {
        document.execCommand('copy');
        layer.msg('复制成功',{icon: 6});
        $("copyId").innerHTML = "";
        $("copyId").setStyle("display","none");
    }
    //copyId是html的div元素
    //或者在复制成功后直接removeElemen('input')
    //原因是: input框不能有disabled属性
    //根据第一条扩展,input的width || height 不能为0;
    //input框不能有hidden属性

text-align:center不能居中问题:
text-align:center主要是可以为文字和内联元素、行内块设置水平居中,即使该文字是在块元素内。
css中的元素一共有三类:块元素、行内块和内联元素。
三者的区别就是:
        块元素可以设置宽高,会独占一行;
        行内块拥有块元素的所有特性,除了无法独占一行;
        内联元素无法设置宽高,不会独占一行。

<div text-align:center>
<div style="display:block"></div>
</div> --------则不能实现居中
<div text-align:center>
<div style="display:inline-block"></div>
</div> --------则能实现居中
```        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值