当前位置: 代码迷 >> J2SE >> java 文件路径有关问题
  详细解决方案

java 文件路径有关问题

热度:92   发布时间:2016-04-24 13:18:39.0
java 文件路径问题
/****

* @return 1.是否自动设置节目名称 2.自动设置节目名称时间间隔 3.是否自动刷新 4.自动刷新时间间隔
*/
public ArrayList readerXML() {
ArrayList<String> multiWindowSettingList = new ArrayList<String>();
SAXBuilder builder = new SAXBuilder(false);
try {
Document doc = builder.build(xmlPath);
Element root = doc.getRootElement();
Element AutoSetName = root.getChild("AutoSetName");
Element AutoRefresh = root.getChild("isAutoRefesh");
String autoSetName = AutoSetName.getAttributeValue("isAutoSetName");
String autoSetNameVal = AutoSetName.getAttributeValue("val");
String autoRefresh = AutoRefresh.getAttributeValue("isAutoRefesh");
String autoRefreshVal = AutoRefresh.getAttributeValue("val");
multiWindowSettingList.add(autoSetName);
multiWindowSettingList.add(autoSetNameVal);
multiWindowSettingList.add(autoRefresh);
multiWindowSettingList.add(autoRefreshVal);
XMLOutputter outputter = new XMLOutputter();
FileOutputStream f = new FileOutputStream(xmlPath);
outputter.output(doc, f);
f.close();
} catch (FileNotFoundException e) {
createXML();
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return multiWindowSettingList;
}


想要xmlPath为路径在绝对路径"d:\config\config.xml"
如果直接赋值为"d:\config\config.xml"文件读取产生异常,
用什么方法可以把它实现了?



------解决方案--------------------
up
------解决方案--------------------
Java code
public   ArrayList   readerXML()   {ArrayList <String>   multiWindowSettingList   =   new   ArrayList <String> ();SAXBuilder   builder   =   new   SAXBuilder(false);try   {java.io.File file=new java.io.File(xmlPath)Document   doc   =   builder.build(file);Element   root   =   doc.getRootElement();Element   AutoSetName   =   root.getChild("AutoSetName");Element   AutoRefresh   =   root.getChild("isAutoRefesh");String   autoSetName   =   AutoSetName.getAttributeValue("isAutoSetName");String   autoSetNameVal   =   AutoSetName.getAttributeValue("val");String   autoRefresh   =   AutoRefresh.getAttributeValue("isAutoRefesh");String   autoRefreshVal   =   AutoRefresh.getAttributeValue("val");multiWindowSettingList.add(autoSetName);multiWindowSettingList.add(autoSetNameVal);multiWindowSettingList.add(autoRefresh);multiWindowSettingList.add(autoRefreshVal);XMLOutputter   outputter   =   new   XMLOutputter();FileOutputStream   f   =   new   FileOutputStream(xmlPath);outputter.output(doc,   f);f.close();}   catch   (FileNotFoundException   e)   {createXML();}   catch   (JDOMException   e)   {e.printStackTrace();}   catch   (IOException   e)   {e.printStackTrace();}return   multiWindowSettingList;}
------解决方案--------------------
这里有路径的处理方法,不知道对你有没有用处。但值得学习
  相关解决方案