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