⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printdemo3.java

📁 java 完全探索的随书源码
💻 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 + -