在我的代码中我做
if (!File.Exists(getSomePath()))
{
MessageBox.Show("... existing" + " " + getSomePath());
this.Close();
}
Run Code Online (Sandbox Code Playgroud)
我可以看到getSomePath()是正确的,但是当我在网络上打开该应用程序时,它说它不存在。当我将文件夹复制到本地驱动器时,它说它确实存在。
这是怎么回事?
我有一个XML文件,其中一些子标记(子节点元素)是可选的.例如
<part>
<note>
</rest>
</note>
<note>
<pitch></pitch>
</note>
<note>
<pitch></pitch>
</note>
</part>
Run Code Online (Sandbox Code Playgroud)
但是当我通过标签读取XML文件时,它会抛出NullPointerException - 因为一些子标签是可选的(例如上面的例子中的休息和音调).我怎样才能过滤掉这个?我无法找到任何方法来查找特定标记名称是否存在元素.即使我有条件检查getElementsByTagName("tag-name")方法是否返回NULL - 仍然它进入条件体并显然抛出异常.我怎么解决这个问题?
java代码是:
if(fstelm_Note.getElementsByTagName("rest")!=null){
if(fstelm_Note.getElementsByTagName("rest")==null){
break;
}
NodeList restElmLst = fstelm_Note.getElementsByTagName("rest");
Element restElm = (Element)restElmLst.item(0);
NodeList rest = restElm.getChildNodes();
String restVal = ((Node)rest.item(0)).getNodeValue().toString();
}else if(fstelm_Note.getElementsByTagName("note")!=null){
if(fstelm_Note.getElementsByTagName("note")==null){
break;
}
NodeList noteElmLst = fstelm_Note.getElementsByTagName("note");
Element noteElm = (Element)noteElmLst.item(0);
NodeList note = noteElm.getChildNodes();
String noteVal = ((Node)note.item(0)).getNodeValue().toString();
}
Run Code Online (Sandbox Code Playgroud)
任何见解或建议都表示赞赏.提前致谢.
我正在尝试使用jquery内容获取某些对象(包括文本)的HTML表单.这是我到现在所得到的:
HTML
<div id="mydiv">
test
<p>foo</p>
<p>bar</p>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$('#mydiv').contents().each(function(){
console.log($(this).html());
console.log($(this).prop("innerHTML"));
console.log($(this).prop("outerHTML"));
});
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?我四处寻找,但找不到任何东西.
提前谢谢您的回答!
我想尽快将我的iPhone应用程序升级到单个通用故事板,以便在新款iPhone上市时随时使用.
我检查了"使用大小类",但我的视图控制器的大小仍然是320 x 568我如何通过示例将大小更改为480 x 640(wAny hRegular)?
根据此文档:http://technet.microsoft.com/en-us/library/ff686200%28v=ws.10%29.aspx File.exists()在smb2网络共享上不准确.我无法更改任何寄存器设置,所以我想处理它.根据该文档,有一个API来从文件系统获取通知.我假设WatchService是此API的Java实现.我对么?
我从jdk示例开始使用WatchDir示例并将其剥离了一下.我只需要知道何时创建和删除文件(我不关心文件修改).为了测试,我在触发新事件时添加了新的File.exists().我也启动一个单独的Thread来测试文件的存在.当我不启动这个分离的线程时,文件存在立即返回true.当额外的线程启动时,它不再准确.我需要一个更准确的文件.检查整个应用程序和所有正在运行的线程.
为了测试,我使用了2台Windows 7 pc(运行java 7)(启用了smb2,这是默认设置).工作目录必须位于远程PC上,并且必须在远程PC上创建文件test.txt(或从另一个文件夹复制)(不使用网络驱动器,而是在PC本身上).
这是我的测试代码:
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.OVERFLOW;
import java.io.File;
import java.io.IOException;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
public class WatchDir
{
private final WatchService _watcher;
private final String _dir;
public WatchDir( String dir ) throws IOException
{
_dir = dir;
_watcher = FileSystems.getDefault().newWatchService();
Paths.get( dir ).register( _watcher, ENTRY_CREATE, ENTRY_DELETE );
System.out.println( "watch registered for dir: " + dir );
} …Run Code Online (Sandbox Code Playgroud) 我的webapp有一个内容安全策略,它将img-src设置为*(从任何地方加载图像),但Chrome仍会阻止某些图像加载...
拒绝加载图像'data:image/webp; base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA ==',因为它违反了以下内容安全策略指令:"img-src*".lg @js?libraries = places,geometry&v = 3&callback = async_req_1:84(匿名函数)@js?libraries = places,geometry&v = 3&callback = async_req_1:119google.maps.Load @js?libraries = places,geometry&v = 3&callback = async_req_1: 21(匿名函数)@js?libraries = places,geometry&v = 3&callback = async_req_1:118(匿名函数)@js?libraries = places,geometry&v = 3&callback = async_req_1:119
如果我在指令中包含'data:',则控制台中不会显示错误.
img-src*data:;
但是,这不是有效的指令.是否有一个img-src有效的CSP值可以满足Chrome或者这可能是一个Chrome错误?我无法在可访问的错误列表中找到任何直接匹配.我猜测这可能与SVG文件中嵌入的图像有关.Firefox和Safari不会出现此行为.
我在c#中编写单元测试. ShouldBeEquivalentTo对于积极的案例是有意义的,但对于否定的案例,你使用什么>我没有找到类似的东西ShouldNotBeEquivalentTo.
我有一个从服务器返回的JSON流,我需要使用JSON.net搜索节点"ID"的特定值来解析数据.我几乎可以使它工作,但不完全是因为返回的结果彼此深深地嵌套 - 这是因为我正在获得一个文件夹结构.我把JSON简化为更简单的版本.我明白了:
{
"data": {
"id": 0,
"name": "",
"childFolders": [{
"id": 19002,
"name": "Locker",
"childFolders": [{
"id": 19003,
"name": "Folder1",
"childFolders": [],
"childComponents": [{
"id": 19005,
"name": "route1",
"state": "STOPPED",
"type": "ROUTE"
}]
}, {
"id": 19004,
"name": "Folder2",
"childFolders": [],
"childComponents": [{
"id": 19008,
"name": "comm1",
"state": "STOPPED",
"type": "COMMUNICATION_POINT"
}, {
"id": 19006,
"name": "route2",
"state": "STOPPED",
"type": "ROUTE"
}, {
"id": 19007,
"name": "route3",
"state": "STOPPED",
"type": "ROUTE"
}]
}],
"childComponents": []
}],
"childComponents": [] …Run Code Online (Sandbox Code Playgroud) I have an IEnumerable<IEnumerable<T>> method called Batch that works like
var list = new List<int>() { 1, 2, 4, 8, 10, -4, 3 };
var batches = list.Batch(2);
foreach(var batch in batches)
Console.WriteLine(string.Join(",", batch));
Run Code Online (Sandbox Code Playgroud)
-->
1,2
4,8
10,-4
3
Run Code Online (Sandbox Code Playgroud)
The problem I've having is that I'm to optimize something like
foreach(var batch in batches)
ExecuteBatch(batch);
Run Code Online (Sandbox Code Playgroud)
by
Task[] tasks = batches.Select(batch => Task.Factory.StartNew(() => ExecuteBatch(batch))).ToArray();
Task.WaitAll(tasks);
Run Code Online (Sandbox Code Playgroud)
or
Action[] executions = batches.Select(batch => new Action(() => ExecuteBatch(batch))).ToArray();
var options = new ParallelOptions …Run Code Online (Sandbox Code Playgroud) 我的真实项目不是使用嵌入式样式或背景颜色.这些已添加用于仅用于故障排除目的.
从下面的代码开始,一切都很好,除了第二个文本输入感觉有点短.所有其他文本输入都会延伸以填充浏览器窗口.我不希望它这样做,但我希望它只是填充我用红色着色的部分.因此一直向右伸展,但不是一直向左伸展.
<label for="phoneNumber">Home Phone</label>
<div style="background:blue;">
<div style="background:yellow; float:left;">(<input style="width:20px;" type="tel" name="ext" id="phoneNumberExt" autocomplete="tel">)</div>
<div style="background:red;"><input type="tel" name="phone" id="phoneNumber" autocomplete="tel"></div>
</div>Run Code Online (Sandbox Code Playgroud)
鉴于我希望文本输入填充100%的父div(即红色区域),我的第一直觉是写,style="width:100%;"但这没有所需的结果.见下文.
<label for="phoneNumber">Home Phone</label>
<div style="background:blue;">
<div style="background:yellow; float:left;">(<input style="width:20px;" type="tel" name="ext" id="phoneNumberExt" autocomplete="tel">)</div>
<div style="background:red;"><input style="width:100%;" type="tel" name="phone" id="phoneNumber" autocomplete="tel"></div>
</div>Run Code Online (Sandbox Code Playgroud)
如何使文本输入填充红色显示的区域?
c# ×4
java ×2
.net ×1
asynchronous ×1
class ×1
css ×1
each ×1
html ×1
javascript ×1
jquery ×1
json ×1
json.net ×1
linq ×1
optional ×1
size ×1
smb ×1
tagname ×1
unit-testing ×1
watchservice ×1
xml ×1