已阅读5页,还剩30页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
如果路径为null就去读取路径 if path null StringBuffertempPath newStringBuffer tempPath append ReadXML class getResource getPath 获取当前class所在的路径 ReadXML class getResource getPath 你可以用这个方法来获取到你当前class的路径 ReadXML可以替换为你自己当前的class名字 if tempPath length 0 如果路径长度 0则路径存在tempPath deleteCharAt 0 tempPath delete tempPath length 8 tempPath length 删除掉 classes tempPath append fileName path tempPath toString 写的比较久了 那时没有加注释习惯 所以 呵呵 现在勉强加上 你可以使用下看 如果不行 你就用 ReadXML class getResource getPath 这个方法获取到路径 获取到后可能为f aaa WEB INF classes然后删除掉 classes再加上你的XML文件名就行了 后面的没有办法一定要写死的 解析1 xml文件 存放在web info目录下 运用文件目录下 StringfileName 1 xml InputStreamReaderreader Resources getResourceAsReader fileName SAXBuilderbuilder newSAXBuilder builder setEntityResolver newSqlMapJarEntityResolver builder setValidation validationEnabled Documentdoc builder build reader Elementroot doc getRootElement Stringrootname root getName rootname sql map config Listchildren root getChildren for inti 0 i children size i Elementchild Element children get i Stringresource getAttributeValue child resource true resource com longtop baseinfo map DictContentSql xml 第三个参数表示这个参数是否是必须的 如果没有这个参数会出错 补充 Ibatis有特别一个类 mon resources resources 专门将文件处理成java文件对象 File InputStream InputStreamReader Properties 和获得该文件的相对路径 相对于classpath 的URL对象 mon resources importjava io importjava util Aclasstosimplifyaccesstoresourcesthroughtheclassloader authorclinton begin publicclassResourcesextendsObject ReturnstheURLoftheresourceontheclasspath paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticURLgetResourceURL Stringresource throwsIOException URLurl null ClassLoaderloader Resources class getClassLoader if loader null url loader getResource resource if url null url ClassLoader getSystemResource resource if url null thrownewIOException Couldnotfindresource resource returnurl ReturnstheURLoftheresourceontheclasspath paramloaderTheclassloaderusedtoloadtheresource paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticURLgetResourceURL ClassLoaderloader Stringresource throwsIOException URLurl null if loader null url loader getResource resource if url null url ClassLoader getSystemResource resource if url null thrownewIOException Couldnotfindresource resource returnurl ReturnsaresourceontheclasspathasaStreamobject paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticInputStreamgetResourceAsStream Stringresource throwsIOException InputStreamin null ClassLoaderloader Resources class getClassLoader if loader null in loader getResourceAsStream resource if in null in ClassLoader getSystemResourceAsStream resource if in null thrownewIOException Couldnotfindresource resource returnin ReturnsaresourceontheclasspathasaStreamobject paramloaderTheclassloaderusedtoloadtheresource paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticInputStreamgetResourceAsStream ClassLoaderloader Stringresource throwsIOException InputStreamin null if loader null in loader getResourceAsStream resource if in null in ClassLoader getSystemResourceAsStream resource if in null thrownewIOException Couldnotfindresource resource returnin ReturnsaresourceontheclasspathasaPropertiesobject paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticPropertiesgetResourceAsProperties Stringresource throwsIOException Propertiesprops newProperties InputStreamin null Stringpropfile resource in getResourceAsStream propfile props load in in close returnprops ReturnsaresourceontheclasspathasaPropertiesobject paramloaderTheclassloaderusedtoloadtheresource paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticPropertiesgetResourceAsProperties ClassLoaderloader Stringresource throwsIOException Propertiesprops newProperties InputStreamin null Stringpropfile resource in getResourceAsStream loader propfile props load in in close returnprops ReturnsaresourceontheclasspathasaReaderobject paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticReadergetResourceAsReader Stringresource throwsIOException returnnewInputStreamReader getResourceAsStream resource ReturnsaresourceontheclasspathasaReaderobject paramloaderTheclassloaderusedtoloadtheresource paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticReadergetResourceAsReader ClassLoaderloader Stringresource throwsIOException returnnewInputStreamReader getResourceAsStream loader resource ReturnsaresourceontheclasspathasaFileobject paramresourceTheresourcetofind throwsIOExceptionIftheresourcecannotbefoundorread returnTheresource publicstaticFilegetResourceAsFile Stringresource throwsIOException returnnewFile getResourceURL resource getFile ReturnsaresourceontheclasspathasaFileobject paramloaderTheclass
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- MT/T 1302-2025连续采煤机掘进成套装备选型技术规范
- 初中七年级生物学《探秘细胞:构建动物生命的基本单位》单元整体教学设计
- 大学本科电气工程及其自动化三年级《AI赋能电力系统经济调度优化》教学设计
- 初中生物学中考专题复习课:“微生物的世界”单元整合教学设计
- 小学五年级英语Robins Advice:构建我的健康生活周读写联动教学设计
- 高中化学高二选修4热力学基础专题突破教学设计
- 初中七年级英语上册Unit 5 Do you have a soccer ball?基于主题意义探究的单元整体教学设计
- 小学三年级综合实践活动《校园小帮手养成记》教学设计与实施
- 2025-2026学年上海市宝山中学高一(下)期中数学试卷(含答案)
- 暑假巩固-第七单元自测练习卷(试卷)2025-2026学年四年级语文下册部编版(含答案)
- 五年级河南下册试卷及答案
- 企业运营中心组织架构及岗位职责
- 《义务教育第二学段数学教学生活化的问题及对策研究》
- 萃智创新方法理论考试题库(含答案)
- GB/T 7341.3-2024电声学测听设备第3部分:短时程测试信号
- 2024年广西电力行业职工职业技能大赛(电力交易员赛项)理论考试题库-中(多选题)
- 11BS3给水工程华北标图集
- DL∕T 695-2014 电站钢制对焊管件
- 建筑施工安全风险辨识分级管控清单表
- 高血压脑出血微创颅内血肿清除术
- MRAS系统标准用户手册
评论
0/150
提交评论