放到哪里都行,
只要你把绝对路径指给它
InputStream in = Jsp1Bean.class.getResourceAsStream("c:\\a1.xml");

解决方案 »

  1.   

    放到哪里都行,
    只要你把绝对路径指给它
    InputStream in = Jsp1Bean.class.getResourceAsStream("c:\\a1.xml");
      

  2.   

    放到哪里都行,
    只要你把绝对路径指给它
    InputStream in = Jsp1Bean.class.getResourceAsStream("c:\\a1.xml");
      

  3.   

    我的代码是这样的:
    package com.inrun.webapp.bean;
    import org.jdom.*;
    import org.jdom.output.*;
    import org.jdom.input.*;
    import java.io.*;
    import java.io.FileInputStream;
    public class Jsp1Bean {
      public void  opXML(){
      SAXBuilder sb=new SAXBuilder();
      FileInputStream in=new FileInputStream("f:\\a1.xml");
      Document doc=sb.build(in);
      }
    }报错:
    unreported exception: java.io.FileNotFoundException; must be caught or declared to be thrown at line 33, column 26
      

  4.   

    加try catch即可
    package com.inrun.webapp.bean;
    import org.jdom.*;
    import org.jdom.output.*;
    import org.jdom.input.*;
    import java.io.*;
    import java.io.FileInputStream;
    public class Jsp1Bean {
      public void  opXML(){
    try {  SAXBuilder sb=new SAXBuilder();
      FileInputStream in=new FileInputStream("f:\\a1.xml");
      Document doc=sb.build(in);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
      

  5.   

    你那是编译错误,不是运行错误,
    没关系的。加上try就可以了。
    相对路径,你可以放到和你的程序同一个目录下
      

  6.   

    private static String sConfigFileName = "Config.xml";
        //得到配置文件Config.xml所在目录. tomcat中是在WEB-INF/classes
        URL confURL = null;
        if (confURL == null)
          confURL = ConfigParserXML.class.getClassLoader().getResource(sConfigFileName);
        if (confURL == null)
          confURL = ConfigParserXML.class.getClassLoader().getResource("/" + sConfigFileName);
        if (confURL == null)
          confURL = Thread.currentThread().getContextClassLoader().getResource(sConfigFileName);
        if (confURL == null)
          confURL = ClassLoader.getSystemResource(sConfigFileName);
        System.out.println(confURL);
    输出的confURL即为相对路径
    file:/D:/Personal/Test/classes/Config.xml注:ConfigParserXML为当前类的类名