为什么我的`getClass()。getResource(" logs")`返回null?

时间:2016-05-19 10:42:17

标签: java file intellij-idea resources

我有这段代码:

this.fileName = getClass().getResource("logs").toURI().toString();

因空指针异常而失败,因为getClass().getResource("logs")返回null

我错过了什么?

enter image description here

1 个答案:

答案 0 :(得分:2)

您正在寻找与getClass().getClassLoader().getResource("logs")类相关的资源。

您可以使用using (XmlReader reader = XmlReader.Create(new StreamReader(myFile.InputStream))) { List<BlogPosts> blogPosts = new List<BlogPosts>(); blogPosts = reader.ReadContentAsAsync(List List<BlogPosts>); } ,也可以使用class ThreadingWorker(threading.Thread): def __init__(self): super(ThreadingWorker,self).__init__() param = config() self.model = param.model self.net = caffe.Net(self.model.deployFile, self.model.caffemodel, caffe.TEST) def run(self): input_data = np.random.rand(1,4,self.model.width,self.model.height) start = time() self.net.forward(data=input_data) print 'Success, took %f seconds' % (time()-start) class MultProcessingWorker(mp.Process): def run(self): param = config() self.model = param.model self.net = caffe.Net(self.model.deployFile, self.model.caffemodel, caffe.TEST) input_data = np.random.rand(1,4,self.model.width,self.model.height) start = time() self.net.forward(data=input_data) print 'Success, took %f seconds' % (time()-start) class NormalWorker(object): '''Using the main thread, no parallelization is being used here''' def __init__(self): param = config() self.model = param.model self.net = caffe.Net(self.model.deployFile, self.model.caffemodel, caffe.TEST) def run(self): input_data = np.random.rand(1,4,self.model.width,self.model.height) start = time() self.net.forward(data=input_data) print 'Success, took %f seconds' % (time()-start) p = NormalWorker() p.run() >> Success, took 0.34 seconds thread = ThreadingWorker() thread.start() >> Success, took 3.54 seconds p = MultProcessingWorker() p.start() >> Success, took 3.45 seconds

(在任何一种情况下,我都不会100%确信当它是文件夹而不是实际资源时它会工作......)