我要做这样一个操作
JSP页面 输入 一条字符串 (很小,简单的一些东西)比如:aaaaaJava类执行 写入和读取操作写入 :
要求保存到 web-inf目录或项目classPath目录下
我是这样写代码的
String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"My.xml";
不加 Thread.currentThread().getContextClassLoader().getResource("").getPath() 可以写入
加了就找不到路径
java.io.FileNotFoundException: E:\Documents%20and%20Settings\Administrator\Workspaces\MyEclipse%208.6\.metadata\.me_tcat\webapps\webopp\WEB-INF\classes\MySQLBinPath.xml (系统找不到指定的路径。)
我觉得应该是取得的地址出现了乱码
正确路径应该是:
E:\Documents and Settings\Administrator\Workspaces\MyEclipse 8.6\.metadata\.me_tcat\webapps\webopp\WEB-INF\classes\
该如何解决或者谁有更好的方法解决这一问题
我的写入代码如下:
XMLWriter writer = null;
OutputFormat format = OutputFormat.createPrettyPrint();
String filePath = Thread.currentThread().getContextClassLoader()
.getResource("").getPath()+"MySQLBinPath.xml";
File file = new File(filePath);
SAXReader reader = new SAXReader();
format.setEncoding("UTF-8"); Document _document = DocumentHelper.createDocument();
Element _root = _document.addElement("MySQLBinPath");
Element _path = _root.addElement("path");
_path.setText(binPath); writer = new XMLWriter(new FileWriter(filePath), format);
writer.write(document);
writer.close();
JSP页面 输入 一条字符串 (很小,简单的一些东西)比如:aaaaaJava类执行 写入和读取操作写入 :
要求保存到 web-inf目录或项目classPath目录下
我是这样写代码的
String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"My.xml";
不加 Thread.currentThread().getContextClassLoader().getResource("").getPath() 可以写入
加了就找不到路径
java.io.FileNotFoundException: E:\Documents%20and%20Settings\Administrator\Workspaces\MyEclipse%208.6\.metadata\.me_tcat\webapps\webopp\WEB-INF\classes\MySQLBinPath.xml (系统找不到指定的路径。)
我觉得应该是取得的地址出现了乱码
正确路径应该是:
E:\Documents and Settings\Administrator\Workspaces\MyEclipse 8.6\.metadata\.me_tcat\webapps\webopp\WEB-INF\classes\
该如何解决或者谁有更好的方法解决这一问题
我的写入代码如下:
XMLWriter writer = null;
OutputFormat format = OutputFormat.createPrettyPrint();
String filePath = Thread.currentThread().getContextClassLoader()
.getResource("").getPath()+"MySQLBinPath.xml";
File file = new File(filePath);
SAXReader reader = new SAXReader();
format.setEncoding("UTF-8"); Document _document = DocumentHelper.createDocument();
Element _root = _document.addElement("MySQLBinPath");
Element _path = _root.addElement("path");
_path.setText(binPath); writer = new XMLWriter(new FileWriter(filePath), format);
writer.write(document);
writer.close();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货