Java Resource路径小结

Java Resource NULL 博文链接:https://xfjt297857539.iteye.com/blog/1415510 立即下载

首先一点很重要,Java中不存在标准的相对路径,各种相对路径取资源的方式都是基于某种规则转化为绝对路劲

然后一点也很重要,绝对不要直接使用绝对路径,否则死得很难看

基于以上两点,总结Resource路径问题无非归结为一点:找基点,也就是在某种环境下(web、j2ee或jar包等)通过合适的方式找到一个稳定的基点,然后通过这个基点找到你要的resource

Java中的基点有哪些呢?大致总结一下有以下几种:

1)classpath

如果你要找的资源在classpath下,那么通过classpath这个基点是比较合适的,而取得这个基点方式主要是通过ClassLoader来,具体方法就是 ClassLoader.getResource(String name),而取得ClassLoader的方式很多,比如:

  • Thread.currentThread().getContextClassLoader()
  • clazz.getClassLoader()
  • ClassLoader. getSystemClassLoader()

ClassLoader找resource的实现原理就是先递归在parent classLoader中从所在classpath里加载resource(最终如何加载JDK未开源),如果所有层级的classLoader都未找到,则调用findResource方法来找,而这个方法是暴露给自制classLoader来现实的,因此给了在classpath之外加载resource的机会。

2) 当前用户目录

就是相对于System.getProperty("user.dir" )返回的路径, 对于一般项目,这是项目的根路径。对于JavaEE服务器,这可能是服务器的某个路径。这个并没有统一的规范! 然而, 默认情况下,java.io 包中的类总是根据当前用户目录来分析相对路径名,如new File("xxx"),就是在 System.getProperty("user.dir" )路径下找xxx文件。因此,通过这种方式来定位文件可能会出现移植问题。

3) Web应用程序的根目录

在Web应用程序中,我们一般通过ServletContext.getRealPath("/" )方法得到Web应用程序的根目录的绝对路径。


掌握了上面几个基点,就能很轻松得定位你要找的resource,只不过要清晰地认识到不要只图一时快活,而不管将来移植的死活,要确保能任何环境下(j2se or web,windows or linux)不出问题。

±10V ADC 输入电路的高共模差分输入电压 这篇文章分析了±10V ADC输入电路的设计需求与挑战,重点讨论了高共模差分输入电压的处理方案。文章首先明确了设计目标,即安全转换±10V差分信号并保持信号完整性,同时克服高共模电压、阻抗匹配和噪声优化等难点。随后详细比较了仪表放大器和差分放大器的性能特点,并提出了器件选型理论。在信号链架构部分,文章通过公式推导阐述了增益设置、共模抑制设计和输入阻抗匹配等关键技术。此外,还建立了噪声源模型,提出了噪声优化措施。最后,文章总结了设计验证方法,并扩展了在工业保护和生物电信号采集等场景的应用。该设计强调根据具体应 阅读详情

相关推荐

Android System Slice应用加载分析,及启用Slice后,锁屏日期第一次开机正常显示,但后面锁屏不显示问题分析

最近发现Android P上锁屏界面,日期不显示,发现从P开始后,出现了Slice来允许应用以模块化,可交互的方式,插入多个使用场景。Android P的system UI 也使用到了这一特性,表现为锁屏时间,日期,勿扰图标,闹钟等。 如何使用Slice 以System UI中KeyguardSliceView.java来说明它的使用方法 首先,我们打开System UI 的mk 文件,可以看到以...

qq_33595823的博客 3041

我的src/main/resource资源文件为什么和src/main/java的文件分层格式不一样呢?怎么修改呢?

直接上干货。你看看你的是不是和下图一样。

CGD_ProgramLife的博客 3041

EMC系列EtherCAT总线运动控制器(二):Motion通讯连接、总线配置及诊断

雷赛-EMC系列EtherCAT总线运动控制器(二):Motion通讯连接、总线配置及诊断

weixin_38570076的博客 1923

java中的资源路径resource path

java在操作文件的时候必然需要知道这个文件在哪里。每种文件就是一种资源,java获取资源的方式有两种: 1.通过java.io包中的类,例如File,其他类和File类似 2.通过Class或者ClassLoader 先看看File类: An abstract representation of file and directory pathnames. User interfaces

coding the code,changing the world 5501

晶晨S905L3S/S905L3SB芯片刷机实战:BL加载工具与线刷固件全解析

本文针对晶晨S905L3S/S905L3SB芯片电视盒子刷机时常见的2%失败问题,提供了两种核心解决方案。一是使用已集成特殊通信协议的专用版USB Burning Tool(如V2.2.5/V2.2.7),二是采用旧版工具配合独立的BootLoader加载工具。文章详细解析了两种方案的原理、操作步骤、固件选择及常见问题排查,旨在帮助用户成功完成刷机,让老旧设备焕发新生。

weixin_29238147的博客 1124

《惠普工作站设置BIOS从U盘装系统》

惠普工作站设置BIOS 惠普工作站在做服务器时应用广泛,本文介绍下其BIOS开机自启动设置,附上图片,以供学习参考。 惠普工作站设置BIOS 启动步骤如下: 第一步:根据需要对BIOS进行更改,并保存 1.重启工作站按F10进入BIOS设置(也可以按ESC键选择进入BIOS设置的选项)。 图1 惠普工作站B...

istrangeboy&begin zero的博客 2万+

Java如何读取resources目录下的文件路径(九种代码示例教程)

Java如何读取resources目录下的文件路径(九种代码示例教程)

努力才是唯一的入场券。 1万+

GAN实战:用Python和TensorFlow打造你的第一个生成对抗网络(附完整代码)

本文是一份详细的GAN实战指南,指导读者使用Python和TensorFlow框架从零开始构建并训练一个生成对抗网络。文章涵盖了环境搭建、MNIST数据预处理、生成器与判别器模型构建、对抗性损失函数定义、训练循环编写以及关键的调试技巧,旨在帮助开发者通过动手实践深入理解GAN的核心原理与实现过程。

php55的博客 488

java resources中的文件路径

实现Java resources中的文件路径 1. 整体流程 在Java开发中,我们经常需要操作resources中的文件,如读取配置文件或者加载资源等。下面是实现Java resources中的文件路径的步骤表格: 步骤 操作 1 获取当前类的ClassLoader 2 使用ClassLoader加载资...

weixin_30762363的博客 493

TMC22系列步进电机驱动设计:从静音原理到硬件实战

步进电机驱动是运动控制系统的核心,其性能直接影响设备的精度、噪音和效率。传统驱动方案如A4988采用方波控制,存在转矩脉动大、运行噪音高等问题。而高性能驱动通过优化电流波形与切换策略,从根本上提升了运动质量。其中,**StealthChop2**技术通过同步MOSFET开关与电机反电动势过零点,实现了近乎无声的低速运行;**SpreadCycle**模式则通过逼近正弦波的电流调节,优化了中高速动态性能。这些技术为3D打印机、CNC机床、自动化设备等对静音和精度有要求的场景提供了关键解决方案。本文以广泛应用的

weixin_31858171的博客 356

RK3588之内存带宽计算及达成率

本章来和大家介绍一下内存带宽的计算与达成率

文艺小少年的博客 1829

java获取resources路径的方法

我们可以使用 java. util. exec ()方法,但是这个方法有一个致命的缺陷,那就是它只能获取一个字符串,但是如果你想要获取更多的字符串,比如你想要获取一行或者一段文本的话,那么你就必须要在上面输入更多的字符串了。(3)打开运行命令行,输入 resource. exec (),如果你的程序还没有执行完,那么我们在运行命令行中输入 resource. exec (),它就会去执行 resource对象的内容。通过上面两种方法的对比,我们可以看到,第二种方法是要比第一种方法简单的多了。

花生日记 7603

C#上位机实战:PLC与检测设备无缝对接,构建产品质量实时判定系统

本文分享了基于C#开发的汽车零部件质量检测系统实现经验。系统采用三层架构:设备层(PLC/视觉相机/三坐标)、通信层(OPC UA/SDK/串口)和应用层(数据采集/判定/存储)。重点解决了三大技术难点:1)通过OPC UA订阅模式将PLC通信延迟从500ms降至50ms;2)反编译厂商Demo破解视觉SDK对接难题;3)采用时间戳+产品ID实现多设备数据同步。系统上线后质检人员减少67%,误判率降至0.5%,数据追溯效率显著提升。文章强调工业场景下稳定性优先于技术复杂度,实用经验值得借鉴。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 811

java resouce_Java Resource路径小结

首先一点很重要,Java中不存在标准的相对路径,各种相对路径取资源的方式都是基于某种规则转化为绝对路劲然后一点也很重要,绝对不要直接使用绝对路径,否则死得很难看基于以上两点,总结Resource路径问题无非归结为一点:找基点,也就是在某种环境下(web、j2ee或jar包等)通过合适的方式找到一个稳定的基点,然后通过这个基点找到你要的resourceJava中的基点有哪些呢?大致总结一下有以下几种...

weixin_39806603的博客 170

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

上一篇: Spring源码学习(二)------ AOP
下一篇: 给老板汇报技术规划的一些要点
cutesource
博客等级 码龄17年 5041粉丝 151原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值