怎样找到Java项目下的xml文件?
在MyEclipse上建了一个Java项目,把一个xml文件map.xml放到src目录下,然后想在com包下的test.java里面newFile("map.xml")...
在MyEclipse上建了一个Java项目,把一个xml文件map.xml放到src目录下,然后想在com包下的test.java里面new File("map.xml"),但总是抛出异常FileNotFoundException。请帮忙解决一下。
上面的问题加相对路径搞定了,new File("\\map.xml"),但是现在读出的xml数据中文出现乱码。 展开
上面的问题加相对路径搞定了,new File("\\map.xml"),但是现在读出的xml数据中文出现乱码。 展开
展开全部
map.xml没加路径吧 或是和你的java执行文件不在一个目录或classpath里
你参考下
public final class InitHibernate {
private static String configFile = "/rmms.hibernate.xml";
private Configuration config;
public void init(){
config=new Configuration().configure(configFile);
config.setProperties(HibernateUtil.getProperties());
}
public SessionFactory buildSessionFactory(){
return config.buildSessionFactory();
}
public Configuration getHibernateConf(){
return config;
}
}
public class DAOConfig {
private static Logger logger = LogManager.getLogger(DAOConfig.class);
private static final String DAO_CONFIG_FILE = "dao.xml";
private static final String DAO_CONFIG_SECTION = "DAO";
public static synchronized HashMap load() {
HashMap<Object, Object> map = new HashMap<Object, Object>();
JFigLocator jfigLocator = new JFigLocator(DAO_CONFIG_FILE);
JFigIF daoConfig = JFig.getInstance(jfigLocator);
Properties prop = daoConfig.getSectionAsProperties(DAO_CONFIG_SECTION);
Enumeration enumSection = prop.keys();
while (enumSection.hasMoreElements()) {
String daoIface = (String) enumSection.nextElement();
String daoImpl = prop.getProperty(daoIface);
try {
Class iface = ClassToolkit.loadClass(daoIface);
Class impl = ClassToolkit.loadClass(daoImpl);
// 将接口作为HashMap索引,实现类作为值
map.put(iface, impl.getConstructor().newInstance());
} catch (ClassNotFoundException e) {
logger.debug("No Class Found =>" + e);
} catch (Exception ex) {
logger.debug("create instance failed =>" + ex);
}
}
return map;
}
}
你参考下
public final class InitHibernate {
private static String configFile = "/rmms.hibernate.xml";
private Configuration config;
public void init(){
config=new Configuration().configure(configFile);
config.setProperties(HibernateUtil.getProperties());
}
public SessionFactory buildSessionFactory(){
return config.buildSessionFactory();
}
public Configuration getHibernateConf(){
return config;
}
}
public class DAOConfig {
private static Logger logger = LogManager.getLogger(DAOConfig.class);
private static final String DAO_CONFIG_FILE = "dao.xml";
private static final String DAO_CONFIG_SECTION = "DAO";
public static synchronized HashMap load() {
HashMap<Object, Object> map = new HashMap<Object, Object>();
JFigLocator jfigLocator = new JFigLocator(DAO_CONFIG_FILE);
JFigIF daoConfig = JFig.getInstance(jfigLocator);
Properties prop = daoConfig.getSectionAsProperties(DAO_CONFIG_SECTION);
Enumeration enumSection = prop.keys();
while (enumSection.hasMoreElements()) {
String daoIface = (String) enumSection.nextElement();
String daoImpl = prop.getProperty(daoIface);
try {
Class iface = ClassToolkit.loadClass(daoIface);
Class impl = ClassToolkit.loadClass(daoImpl);
// 将接口作为HashMap索引,实现类作为值
map.put(iface, impl.getConstructor().newInstance());
} catch (ClassNotFoundException e) {
logger.debug("No Class Found =>" + e);
} catch (Exception ex) {
logger.debug("create instance failed =>" + ex);
}
}
return map;
}
}
展开全部
在XML上部有一个设置本页字符集的设置。你把它换成和你浏览器一致就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?xml version="1.0" encoding="UTF-8"?>
改成
<?xml version="1.0" encoding="GBK"?>
改成
<?xml version="1.0" encoding="GBK"?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有放图,看一下又不会怀孕。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询