我正在尝试使用以下代码复制文件:
File targetFile = new File(targetPath + File.separator + filename);
...
targetFile.createNewFile();
fileInputStream = new FileInputStream(fileToCopy);
fileOutputStream = new FileOutputStream(targetFile);
byte[] buffer = new byte[64*1024];
int i = 0;
while((i = fileInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, i);
}
Run Code Online (Sandbox Code Playgroud)
对于某些用户targetFile.createNewFile,此异常中的结果为:
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
Run Code Online (Sandbox Code Playgroud)
文件名和目录名似乎是正确的.在targetPath执行复制代码之前,甚至检查目录是否存在,文件名如下所示:AB_timestamp.xml
用户具有写入权限,targetPath并且可以使用操作系统轻松复制文件.
因为我无法访问机器,但这种情况发生了,并且无法在我自己的机器上重现问题.我转向您提供有关此异常原因的提示.
目前我有这个方法:
static boolean checkDecimalPlaces(double d, int decimalPlaces){
if (d==0) return true;
double multiplier = Math.pow(10, decimalPlaces);
double check = d * multiplier;
check = Math.round(check);
check = check/multiplier;
return (d==check);
}
Run Code Online (Sandbox Code Playgroud)
但是这种方法失败的checkDecmialPlaces(649632196443.4279, 4)原因可能是因为我在基数为2的数字上进行了10次数学运算.
那么如何才能正确完成这项检查呢?
我想到获得double值的字符串表示,然后用regexp检查 - 但这感觉很奇怪.
编辑: 谢谢你的所有答案.在某些情况下,我真的得到了一个双倍,在这些情况下,我实现了以下内容:
private static boolean checkDecimalPlaces(double d, int decimalPlaces) {
if (d == 0) return true;
final double epsilon = Math.pow(10.0, ((decimalPlaces + 1) * -1));
double multiplier = Math.pow(10, decimalPlaces);
double check = d * multiplier;
long checkLong = (long) …Run Code Online (Sandbox Code Playgroud) 今天我偶然发现了在Javascript中访问DOM元素的可能性,只需通过它的id,例如:
elementid.style.backgroundColor = "blue"
Run Code Online (Sandbox Code Playgroud)
我测试了一个非常短的片段,如果这适用于IE,Firefox和Chrome - 它确实如此.这是我使用的片段:
<html><head>
<script>
function highlight() {
content.style.backgroundColor = "blue";
content.style.color = "white";
}
</script>
</head>
<body>
<div id="content">test content</div>
<div onclick="highlight()">highlight content</div>
</body></html>
Run Code Online (Sandbox Code Playgroud)
所以我想知道document.getElementById('elementid')应该使用哪些情况(或类似的框架替换,如$())以及直接访问的缺点是什么.
我无法找到任何有用的文档.无处不在getElementById或使用框架方法.