获取文件路径问题 如图,怎样把 “人员信息列表查询接口回执报文.v1.xml”这个xml文件地址在TestMain这个main方法里拿出来,我想要的结果是 "E:\workspace\TestXML\src\xml\人员信息列表查询接口回执报文.v1.xml" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 File file=new File("src/xml/人员信息列表查询接口回执报文.v1.xml");String s = file.getAbsolutePath();System.out.println(s);这样不行?怎么可能没有src,你路径没有写对。 你既然都拿到FIle对象了 还愁拿不到路径? 你直接获取绝对路径 也就是完整路径 File file=new File("人员信息列表查询接口回执报文.v1.xml");String s = file.;System.out.println(s); 有这样的没,就是只传一个文件名找 貌似是我犯晕了Thanks everybody ! File file = new File(Test.class.getResource("/").getFile(),"xml/text.xml"); 这个方法会产生中文乱码,用URLDecoder.decode(configPath,"utf-8");处理一下就好了 String path = this.getClass().getResource("/").toString();path = path.substring(path.indexOf("/"),path.length());//根路径这样能获取到项目class的绝对路径 // 这个是获取路径的方法URL url = TestMain.class.getResource("/xml/xxx.xml");System.out.println(url.getPath());// 这个是获取流的方法InputStream is = TestMain.class.getResourceAsStream("/xml/xxx.xml");System.out.println(is); 请大家帮忙修改,不知道怎么改了。。谢谢!!!! action中 使用属性驱动还是模型驱动啊? 大家推荐一下啊(ext)学习用书 100分!JSP如何调用SQL server的存储过程,并返回调用结果? 菜鸟的运行问题! 如何限制某一IP地址连续恶意访问网站. 求jive3.1.3的license 怎样通过连接池实现在不同数据库之间的转换? resin 配置虚拟主机?很急在线等.送分. 在jsp中怎样统计在线人数? sendRedirect中setHeader方法的问题 webservice问题!
String s = file.getAbsolutePath();
System.out.println(s);
这样不行?怎么可能没有src,你路径没有写对。
String s = file.;
System.out.println(s);
有这样的没,就是只传一个文件名找
String path = this.getClass().getResource("/").toString();
path = path.substring(path.indexOf("/"),path.length());//根路径这样能获取到项目class的绝对路径
URL url = TestMain.class.getResource("/xml/xxx.xml");
System.out.println(url.getPath());
// 这个是获取流的方法
InputStream is = TestMain.class.getResourceAsStream("/xml/xxx.xml");
System.out.println(is);