文本文件打印 Java Applet 在 Windows 操作系统中不起作用 [英] Text FIle printing Java Applet not working in windows OS

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

问题描述

我创建了一个 java 小程序,用于将文本文件内容从远程位置复制到本地计算机.它工作正常,并尝试使用 dos 命令(Windows XP)进行打印.它不工作,但在 Ubuntu 操作系统中工作正常.你能帮我改进我的代码吗..

这是我的代码

尝试{String server=this.getParameter("SERVER");String filename=this.getParameter("FILENAME");String osname=System.getProperty("os.name");字符串文件路径="";URL url = 新 URL("http://10.162.26.8/openLypsaa/reports/report_oc/127.0.0.1_sys_ANN_milkbill");URLConnection 连接 = url.openConnection();InputStream is = connection.getInputStream();if("Linux".equals(osname)){filePath = "/tmp/OLFile";}别的{filePath = "C:/WINDOWS/Temp/OLFile";}OutputStream output = new FileOutputStream(filePath);字节[]缓冲区=新字节[256];int bytesRead = 0;while ((bytesRead = is.read(buffer)) != -1){System.out.println(bytesRead);output.write(buffer, 0, bytesRead);}输出关闭();if("Linux".equals(osname))Runtime.getRuntime().exec("lp/tmp/OLFile").waitFor();别的Runtime.getRuntime().exec("打印 C:/WINDOWS/Temp/OLFile").waitFor();}

解决方案

在windows中你想使用:filePath = "C:\\WINDOWS\\Temp\\OLFile";>

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

你也可以谷歌一下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 Applet 在 Windows 操作系统中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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