




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 出版业的生产流程管理考核试卷
- 锡冶炼中的废物资源化考核试卷
- 金属制品在建筑D打印中的材料研发考核试卷
- 防晒伞结构与性能考核试卷
- 妇产科手术麻醉
- 卫生间空间功能自我分析
- 医院民生实事工作专题汇报
- 诊断学基础:肝脏疾病
- 麻醉科业务培训体系
- 传染病预防控制体系构建
- uni-app移动应用开发课件 7-智慧环保项目
- 2025年厦门大学嘉庚学院图书馆员招考高频重点提升(共500题)附带答案详解
- 《oracle性能优化》课件
- 小学生手工剪纸课件
- 中药结肠透析治疗慢性肾衰竭的技术规范
- 2024年广东省广州市中考英语真题卷及答案解析
- 化工设备机械基础习题及参考答案
- 《课件旅游法培训》课件
- 高中生物(部编版)选择性必修3知识清单(问答版)
- 山东师范大学《高级英语(二)》2021-2022学年第一学期期末试卷
- 手术体位摆放原则及注意事项
评论
0/150
提交评论