FileNotFoundException是否以某种方式成为IOException的"子异常"?
这是我的代码打开给定路径上的文件的输入流:
method(){
FileInputStream fs;
try {
fs = new FileInputStream(path);
//
fs.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我可以忽略FileNotFound而只是捕获IOException呢?FNFException是否是IOException的一部分?
如果我在我的方法中抛出IOException,而不是捕获异常?
method() throws IOException{
FileInputStream fs;
fs = new FileInputStream(path);
//
fs.close();
}
Run Code Online (Sandbox Code Playgroud)
我可以继续在这样的调用方法中捕获FileNotFoundException吗?
try {
method();
}catch (FileNotFoundException e1) {}
Run Code Online (Sandbox Code Playgroud)
感谢您提供的任何帮助!
我试图弄清楚如何设计一个能够以O((n + s)log n)复杂度完成此任务的算法.是交叉点的数量.我试过在网上搜索,却找不到东西.
无论如何,我意识到拥有一个好的数据结构是关键.我在java:TreeMap中使用Red Black Tree实现.我还使用着名的(?)扫描线算法来帮助我处理我的问题.
让我先解释一下我的设置.
我有一个调度程序.这是一个PriorityQueue,我的圈子根据最左边的坐标排序(升序).scheduler.next()
基本上轮询PriorityQueue,返回下一个最左边的圆圈.
public Circle next()
{ return this.pq.poll(); }
Run Code Online (Sandbox Code Playgroud)
我这里还有一个包含4n个事件点的数组.授予每个圆圈有2个事件点:大多数左x和最右x.调度程序有一个方法sweepline()来获取下一个事件点.
public Double sweepline()
{ return this.schedule[pointer++]; }
Run Code Online (Sandbox Code Playgroud)
我也有状态.扫描线状态更精确.根据该理论,状态包含有资格相互比较的圆圈.在整个故事中拥有扫描线的关键在于你能够排除很多候选人,因为他们根本不在当前圈子的半径范围内.
我用一个实现了状态TreeMap<Double, Circle>
.双重是circle.getMostLeftCoord().
此TreeMap保证O(log n)用于插入/删除/查找.
算法本身的实现方式如下:
Double sweepLine = scheduler.sweepline();
Circle c = null;
while (notDone){
while((!scheduler.isEmpty()) && (c = scheduler.next()).getMostLeftCoord() >= sweepLine)
status.add(c);
/*
* Delete the oldest circles that the sweepline has left behind
*/
while(status.oldestCircle().getMostRightCoord() < sweepLine)
status.deleteOldest();
Circle otherCircle;
for(Map.Entry<Double, Circle> entry: status.keys()){
otherCircle = entry.getValue();
if(!c.equals(otherCircle)){ …
Run Code Online (Sandbox Code Playgroud) 我正在尝试显示从服务器收到的HTML.然而,目前的代码只工作了很少数和简单的 HTML代码(例如恶意的请求页).
这是一个非常简单的HTML示例,我无法使用当前代码显示该示例.
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.be/index.html?gfe_rd=cr&ei=uhoTU6CaDoSNOrHrgeAL">here</A>.
</BODY></HTML>
Run Code Online (Sandbox Code Playgroud)
这是我的代码在一个内部运行JFrame
.
JEditorPane ed1 = new JEditorPane("text/html", content);
add(ed1);
setVisible(true);
setSize(600,600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Run Code Online (Sandbox Code Playgroud)
请注意,这content
只是一个字符串,每行HTML都相互连接.像这样:content = "<HTML>.............</HTML>"
可能有更优雅的解决方案来获取服务器响应并显示它们.但是,我被限制在java.io
和java.net
包裹.
有什么方法可以找出导致崩溃的结果吗?我现在尝试多次运行脚本,并且在完成随机工作后似乎崩溃了.
如你所见,这没有任何帮助.
至于记忆:我正在尝试构建一个包含3400万条目的矩阵.我在执行期间监视了内存使用情况,得出的结论是内存没有大的增加.记忆力恒定在约580mb.
崩溃只发生在R工作室.不在R解释器中.
java ×4
algorithm ×1
entity ×1
fatal-error ×1
final ×1
geometry ×1
html ×1
intersection ×1
ioexception ×1
persistence ×1
r ×1
rstudio ×1
swing ×1