用System.out.println(System.getProperty("user.dir"));
看一下你运行这个java程序时的当前路径,要么你把文件放在这个当前路径下,要么用绝对路径。

解决方案 »

  1.   

    package iprcapplet;import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.applet.*;
    import java.io.*;import Abstract.*;
    import RouterLayer.AgentClient.*;
    import RouterLayer.util.*;
    import KQMLLayer.*;
    import ProtocolLayer.*;import RouterLayer.AgentClient.Example.RCApplet.*;
    import RouterLayer.AgentClient.Example.RCApplet.extawt.*;public class IPRCApplet extends Applet {        public static void main(String args[]) {
              IPRCFrame frame=new IPRCFrame("iprcapplet.IPRCApplet");
              frame.setVisible(true) ;        }        // invoked by applet
            public IPRCApplet()  {
            }        public void init()  {
        try  {
                String routername = getParameter("RouterName");
                String host = getParameter("RouterHost");
                String port = getParameter("RouterPort");
                String regname = getParameter("RegistrarName");
                String regport = getParameter("RegistrarPort");
                String description = getParameter("Description");            if((routername == null) || (host == null) || (port == null))  {
                                    showStatus("Invalid Applet Parameters. Check the parameters");
                                    System.out.println("Invalid Applet Parameters. Check the parameters");                                destroy();
                }                        String ftpConId = getParameter("FTPConName");
                            String ftpConRemotePath = getParameter("RemotePath");
                            String ftpConUserName = getParameter("UserName");
                            String ftpConHost = getParameter("FTPHost");
                            String ftpConPort = getParameter("FTPPort");                        int ftpportno = 21;
                            if(ftpConPort != null)  {
                                    ftpportno = getInt(ftpConPort);
                            }                        FTPCon appletFTPCon = new FTPCon(ftpConId,ftpConRemotePath,ftpConHost,ftpportno,ftpConUserName,null,null,null,0);            Address routeraddress = new Address(routername,host,getInt(port),"MessageRouter",description);
                Address registraraddress = new Address(regname,host,getInt(regport),"MessageRouter",description);
                            IPRCFrame frame = new IPRCFrame(routeraddress,registraraddress,appletFTPCon);
          frame.setVisible(true);    } catch (Exception e) { showStatus(e.toString()); }  }        protected int getInt(String str) {
                    return (Integer.valueOf(str)).intValue();
            }}
    E:/test/IPRCApplet/IPRCApplet.jpx,然后所有的java文件放在iprcapplet包中
      

  2.   

    加入System.out.println(System.getProperty("user.dir"));
    显示路径 E:\test\IPRCAppletline 54: IPRCFrame frame=new IPRCFrame("E:\test\IPRCApplet");
    出错:illegal escape character at line 54 (54:49)
      

  3.   

    你把那个文件路径传进去做什么呢?
    文件路径按系统文件路径的方式写就行了!
    如:c:\a\b.xml 写成:c:\\a\\b.xml。
    文件要有后缀名的。
    还有一个方法:file = new File(".");
    System.out.println("real path:"+file.getAbsolutePath());
    查看一下当前的真实路径,然后根据相对路径计算出你的文件的位置!
      

  4.   

    我要的是一个地址文件
           File file = new File("AddressFile");
           System.out.println("real path:"+file.getAbsolutePath());
    显示:real path:E:\test\IPRCApplet\AddressFile        IPRCFrame frame=new IPRCFrame("E:\\test\\IPRCApplet\\AddressFile");
            frame.setVisible(true) ;   运行后java.lang.NullPointerException
      

  5.   

    你的文件是已经存在的吗?存在于物理磁盘上吗?
    看不清你到底想干什么?
    再输出异常的时候,用:e.printStackTrace(System.out);这样会把错误显示的更清楚些!