XDocument.Load 使用版本1.1而不是1.0的XML文件时抛出异常:
Unhandled Exception: System.Xml.XmlException: Version number '1.1' is invalid. Line 1, position 16.
任何干净的解决方案来解决错误(没有正则表达式)并加载文档?
我有这个javascript代码,但当我发送这个:asd.JPG正则表达式失败了我..
if (data.match(/([^\/\\]+)\.(jpg|jpeg|gif|png|tiff|tif)$/i))
return { filename: RegExp.$1, ext: RegExp.$2 };
else
return { filename: "invalid file type", ext: null };
Run Code Online (Sandbox Code Playgroud)
所以我希望正则表达式将扩展名视为不区分大小写.我尝试了这个,但它失败了:
data.match(/([^\/\\]+)\.(?i)(jpg|jpeg|gif|png|tiff|tif)$/i)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
为什么每次打印时都遵循程序I'm string而不是I'm object.或I'm int.?
public class Demo {
public Demo(String s){
System.out.println("I'm string");
}
public Demo(int i){
System.out.println("I'm int.");
}
public Demo(Object o){
System.out.println("I'm object.");
}
public static void main(String[] args) {
new Demo(null);
}
}
Run Code Online (Sandbox Code Playgroud)
另外,如果我取代int用Integer.它给出了错误,The constructor Demo(String) is ambiguous.为什么?
在ES5中,我可以检查window对象上是否存在"类"(构造函数):
if (window.MyClass) {
... // do something
}
Run Code Online (Sandbox Code Playgroud)
在ES6中,根据本文,全局声明的类是全局变量,但不是全局对象的属性(window在浏览器上):
但是现在还有全局变量不是全局对象的属性.在全局范围内,以下声明会创建此类变量:
let声明const声明- 类声明
所以,如果我不能使用if (window.MyClass),有没有办法做同样的事情?
实际上有没有一个正确的方法来做到这一点,而不使用窗口对象?
我需要将以前的网址重定向到上一页.我有网址喜欢www.mysite.com/users/register/#1.
我document.referrer用来获取前一个url,但它不返回hash part(#1).如何获取包含哈希部分的上一个url?
我正面临JVM的奇怪行为.我想更改用户目录,即查找文件的目录,通常对应于java运行命令的路径.
所以我写了下面的代码:
System.setProperty("user.dir", "/tmp/");
File f = new File("myfile");
System.out.println(f.exists());
System.out.println(f.getCanonicalFile().exists());
Run Code Online (Sandbox Code Playgroud)
该文件/tmp/myfile存在并且可由JVM读取,但如果我在运行该代码时不在/tmp/,则结果为:
false true
它们是相同的文件,Java能够检索它的正确规范形式,但相对的不存在,而规范的存在.
这是一个错误吗?有没有办法可靠地更改JVM用户目录?
更改代码不是一个选项,因为我正在尝试运行外部库.
我有下面的代码,并noImplicitAny:true在tsconfig:
let o = {a: 3};
// works fine
o['a'] = 3;
// reports an error
// Error:(4, 1) TS7017:Index signature of object type implicitly has an 'any' type.
o['b'] = 3;
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思?
这是在TypeScript游乐场 - 确保单击选项并设置noImplicitAny(似乎不记得可共享链接中的选项).
TypeScript 中是否可以将字符串联合类型转换为数字联合类型?
例如给定一个联合类型 A:
type A = '7' | '8' | '9'
Run Code Online (Sandbox Code Playgroud)
转换成:
type B = 7 | 8 | 9
Run Code Online (Sandbox Code Playgroud)
中的数字A可以是任何数字,而不仅仅是数字或整数。
我写了简单的Java Downloader,我在速度方面遇到了一些问题.
首先,速度还可以 - 就像我使用浏览器下载此文件一样.但经过一段时间后,速度会下降很多,并且每两秒钟更换一次 - 从42kb/s到64kb/s,从64kb/s到42kb/s.
我的代码:
InputStream is = null;
FileOutputStream os = null;
os = new FileOutputStream(...);
URL u = new URL(...);
URLConnection uc = u.openConnection();
is = uc.getInputStream();
final byte[] buf = new byte[1024];
for(int count = is.read(buf);count != -1;count = is.read(buf)) {
os.write(buf, 0, count);
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能最大限度地提高下载速度?
UPDATE
文件大小从1到大约100MB不等.我将缓冲区增加到65536,它是一样的.
关于测量:我每3秒检查写入多少字节,然后除以3和1024 - 它给我kb/s
我试过用NumberFormat和DecimalFormat.即使我使用的是en-In区域设置,数字也会以西方格式进行格式化.有没有选项来格式化数字格式的数字呢?
恩-我想NumberFormatInstance.format(123456)给1,23,456.00的,而不是123,456.00(例如,使用描述的系统这个维基百科页面).
java ×4
javascript ×4
typescript ×2
c# ×1
class ×1
ecmascript-6 ×1
formatting ×1
io ×1
linq ×1
linq-to-xml ×1
regex ×1
xml ×1