如何在其他计算机上运行java文件的.exe文件

时间:2013-08-07 08:46:30

标签: java eclipse exe executable-jar

我在eclipse中开发了一个java代码。我的代码使用server_ip从.txt文件中读取数据。我已经创建了代码的可执行jar文件,然后使用launch4j创建了一个.exe文件。 .exe文件显示数据,如果我在我的笔记本电脑中运行它,但如果我在其他电脑上运行它,它不会显示任何数据。然后它显示零点异常。我的操作系统是Windows 7-32位。我在这里给我的代码。请给我解决方案。

package remotedata;

import java.awt.*; 

import java.net。; import java.io。;

public class remotedataread extends Frame
{ 
    public static void main(String[] args)
            throws InterruptedException, IOException{

        BufferedReader br = null;
        TextArea FileText = 
        new TextArea(" Content of the File \'temp1.txt\' :"); 

        try
        {   
            URL url = 
                new URL("file://server_ip/path_file.txt");

                        InputStream is = url.openStream(); 
                        br = new BufferedReader(new InputStreamReader(is));
                     /*   String line = null;
                        while (true) {
                            line = br.readLine();
                            if (line == null) {
                                //wait until there is more of the file for us to read
                                Thread.sleep(1000);
                            }
                            else {
                                System.out.println(line);
                            }
                        }*/
        }


        catch (MalformedURLException e)
        {
            System.out.println("Bad URL");
        }
        catch (IOException e)
        {
            System.out.println("IO Error : "+e.getMessage());
        }   

        FileText.setBackground(Color.white);
        FileText.append(String.valueOf('\n'));

        Frame f = new Frame("server data");
        f.setSize(200,200);
        f.add(FileText); 
        f.setVisible(true);

        try
        {
            String s;
            s=null;
            boolean eof = false;
            //while (true) {
            s = br.readLine();
            System.out.println("Time    Temperature");
            while( !eof )
            {
                FileText.append(s + String.valueOf('\n'));
                try
                {
                    s = br.readLine();
                    if ( s == null )
                    {
                                //  eof = true;
                    //  br.close();
                         Thread.sleep(1000);

                    }
                    else{
                        //System.out.println("Time  Temperature");
                        System.out.println(s);
                    }

                }
                catch (EOFException eo)
                        {
                                eof = true;
                        }
                catch (IOException e)
                        {
                                System.out.println("IO Error : "+e.getMessage());
                        }
            }
            //}

        }
        catch (IOException e)
                {
                        System.out.println("IO Error : "+e.getMessage());
                }

    } 

}

2 个答案:

答案 0 :(得分:0)

也许,你的应用程序无法连接到其他节点..因此它会抛出NullPointer异常。确保计算机在网络中

答案 1 :(得分:0)

你的问题似乎在这里:

 URL url = 
            new URL("file://server_ip/path_file.txt");

                    InputStream is = url.openStream(); 
                    br = new BufferedReader(new InputStreamReader(is));

网址“file://server_ip/path_file.txt”在您的笔记本电脑上有效,但在其他电脑上无效