文本文件印刷Java小程序无法在Windows操作系统工作 [英] Text FIle printing Java Applet not working in windows OS

查看:147
本文介绍了文本文件印刷Java小程序无法在Windows操作系统工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Java小程序的拷贝从远程位置到本地计算机上的文本文件的内容。其做工精细,并尝试使用DOS命令(Windows XP)中进行打印。它不工作,但其在Ubuntu操作系统工作正常。你可以帮我提高我的code ..

下面是我的code

  {尝试
            字符串服务器= this.getParameter(服务器);
            字符串文件名= this.getParameter(文件名);            串OSNAME = System.getProperty(os.name);
            串文件路径=;            网址URL =新的URL(http://10.162.26.8/openLypsaa/reports/report_oc/127.0.0.1_sys_ANN_milkbill);
            URLConnection的连接= url.openConnection();
            InputStream为= connection.getInputStream();            如果(Linux的.equals(OSNAME))
            {
                文件路径=/ tmp目录/ OLFile
            }
            其他
            {
                文件路径=C:/ WINDOWS /温度/ OLFile            }            OutputStream的输出=新的FileOutputStream(文件路径);            字节[]缓冲区=新的字节[256];
            INT读取动作= 0;
            而((读取动作= is.​​read(缓冲液))!= - 1)
            {
                的System.out.println(读取动作);
                output.write(缓冲液,0,读取动作);
            }
            output.close();    如果(Linux的.equals(OSNAME))
                调用Runtime.getRuntime()EXEC(LP的/ tmp / OLFile)WAITFOR()。
            其他
                调用Runtime.getRuntime()EXEC(打印C:/ WINDOWS /温度/ OLFile)。WAITFOR();
         }


解决方案

在窗口中,您想使用文件路径=C:\\\\ WINDOWS \\\\ \\\\温度OLFile;

 调用Runtime.getRuntime()EXEC(打印C:\\\\ WINDOWS \\\\ \\\\温度OLFile)。WAITFOR();

您也可以google一下 PathSeparator

I am created a java applet for copy a text file content from remote location to local computer. Its working fine and also try to print using dos command(Windows XP). Its not working but its working fine in Ubuntu OS. Can you please help me to improve my code..

Here is my code

try {
            String server=this.getParameter("SERVER");
            String filename=this.getParameter("FILENAME");

            String osname=System.getProperty("os.name");
            String filePath="";

            URL url = new URL("http://10.162.26.8/openLypsaa/reports/report_oc/127.0.0.1_sys_ANN_milkbill");
            URLConnection connection = url.openConnection();
            InputStream is = connection.getInputStream();

            if("Linux".equals(osname))
            {
                filePath = "/tmp/OLFile";
            }
            else
            {
                filePath = "C:/WINDOWS/Temp/OLFile";

            }

            OutputStream output = new FileOutputStream(filePath);

            byte[] buffer = new byte[256];
            int bytesRead = 0;
            while ((bytesRead = is.read(buffer)) != -1)
            {
                System.out.println(bytesRead);
                output.write(buffer, 0, bytesRead);
            }
            output.close();

    if("Linux".equals(osname))
                Runtime.getRuntime().exec("lp /tmp/OLFile").waitFor();
            else
                Runtime.getRuntime().exec("print C:/WINDOWS/Temp/OLFile").waitFor();
         }

解决方案

In windows you would like to use: filePath = "C:\\WINDOWS\\Temp\\OLFile";

and

Runtime.getRuntime().exec("print C:\\WINDOWS\\Temp\\OLFile").waitFor();

You can also google about PathSeparator.

这篇关于文本文件印刷Java小程序无法在Windows操作系统工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆