【问题标题】:how to run .exe file of a java file in other computers如何在其他计算机上运行java文件的.exe文件
【发布时间】:2013-08-08 13:20:53
【问题描述】:

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

打包远程数据;

import java.awt.*; 

导入 java.net.; 导入 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());
                }

    } 

}

【问题讨论】:

  • 空指针异常发生在哪一行? jar 文件是否也可以正常工作?
  • 不,jar 文件和 exe 都不能在其他电脑上运行。这是错误:I0 错误:连接被拒绝:在 remotedata.remotedataread.main<60>

标签: java eclipse exe executable-jar


【解决方案1】:

你的问题似乎在这里:

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

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

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

【讨论】:

  • 解决方案应该是什么?你能帮我吗?
  • 您必须使用正确的 url 来归档,目前您提供了执行机器上文件的路径。如果这是远程服务器上的文件,则需要提供远程 ip 或 url。
  • 但是当 .exe 文件运行时,它显示错误:I0 错误:连接被拒绝:远程数据中的线程“main”java.lang.NullpointerExcwption 异常。远程数据读取.main
  • 尝试将您的 url file://server_ip/path_file.txt 放在笔记本电脑和其他 PC 上的 webbrowser 中,您会看到不同之处。该异常类似于 URL 的 FileNotFound 异常。我认为如果你用正确的 ip 替换“server_ip”,它应该可以在同一网络中的每台电脑上工作
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2018-01-06
    • 1970-01-01
    相关资源
    最近更新 更多