📄 printdemo3.java
字号:
// PrintDemo3.java
import java.io.*;
class PrintDemo3
{
static String s = "This paragraph is being sent to the printer. " +
"I'll bet you didn't think there was such an " +
"easy way to accomplish this task. The trick " +
"is to create a FileWriter object that's " +
"connected to a printer device, and then a " +
"PrintWriter object that's connected to the " +
"FileWriter. Obviously, this isn't very " +
"portable.";
public static void main (String [] args)
{
try
{
FileWriter fw = new FileWriter ("LPT1:");
PrintWriter pw = new PrintWriter (fw);
int i, len = s.length ();
for (i = 0; len > 80; i += 80)
{
pw.print (s.substring (i, i + 80));
pw.print ("\r\n");
len -= 80;
}
if (len > 0)
{
pw.print (s.substring (i));
pw.print ("\r\n");
}
pw.close ();
}
catch (IOException e)
{
System.out.println (e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -