下面这段代码可以读CON(控制台输入设备),COM1和COM2和CON都是特殊的设备文件,应该可以。 import java.io.*; import java.util.zip.*; public class test { public static void main(String[] args)throws Exception { FileInputStream in = new FileInputStream("CON"); for(;;) { int r = in.read(); if (r == -1) break; System.out.write(r); if (r=='\n') System.out.flush(); } }}
用标准的FileInputStream/FileOutputStream读写"COM1","COM2"...
import java.io.*;
import java.util.zip.*;
public class test
{
public static void main(String[] args)throws Exception
{
FileInputStream in = new FileInputStream("CON");
for(;;)
{
int r = in.read();
if (r == -1)
break;
System.out.write(r);
if (r=='\n')
System.out.flush();
}
}}