首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java 文件路径有关问题

2011-12-23 
java 文件路径问题/**** ** @return 1.是否自动设置节目名称 2.自动设置节目名称时间间隔 3.是否自动刷新

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;}
[解决办法]
这里有路径的处理方法,不知道对你有没有用处。但值得学习

热点排行