这是作业题吗?
现实中这样做有意义吗?
对于图片资源,IE会自动缓存到一个固定的文件夹下面的,你如果是第一次打开某个页面会慢点(因为要加载图片、缓存图片),第二次就会稍显快点了(因为不需要加载图片、缓存图片),并且根据你设置的缓存大小,IE会做定期的清理的(win2000的C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files目录下)你的做法没有起到提高效率的目的,因为你把图片存储下来,访问结束又删除(且不论这个是否能够做到),这没有起到缓存的目的,实际意义不大

解决方案 »

  1.   

    下面是PrintFileTest.java的内容package printfiletest;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;/*
     * PrintFileTest.java
     *
     * Created on 12.04.04
     */
    import java.applet.Applet;
    import java.awt.Graphics;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import java.io.*;public class PrintFileTest
        extends Applet {
      private boolean isStandalone = false;private String TMP_FILE="C:\\pics\\map20.jpg";
      //
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
            (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public PrintFileTest() {
      }  //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }  //Component initialization
      private void jbInit() throws Exception {
      }  //Start the applet
      public void start() {
        printMap();
      }  //Stop the applet
      public void stop() {
      }  //Destroy the applet
      public void destroy() {
      }  //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }  //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  //写的程序
      public void printMap() {
        //String filename = TMP_FILE;
        //获取HTML中的APPLET中的param
        String filename = TMP_FILE;
        //////
        String str;
         //构建打印请求属性集
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        //设置打印格式,
        DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
        //查找所有的可用打印服务
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor,
            pras);
        //定位默认的打印服务
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        //显示打印对话框
        PrintService service = ServiceUI.printDialog(null, 200, 200, printService,
                                                     defaultService, flavor, pras);
        if (service != null) {
          try {        DocPrintJob job = service.createPrintJob();//创建打印作业
            FileInputStream fis = new FileInputStream(filename);//构造待打印的文件流
            DocAttributeSet das = new HashDocAttributeSet();        Doc doc = new SimpleDoc(fis, flavor, das);//建立打印文件格式
            // PageFormat format = job.pageDialog(attributes);
            job.print(doc, pras);//进行文件的打印
          }
          catch (Exception e) {
            e.printStackTrace();
          }    }
      }  //
      public void paint(Graphics g) {
        //Draw a Rectangle around the applet's display area.
        g.drawRect(0, 0, size().width - 1, size().height - 1);    //Draw the current string inside the rectangle.
        //g.drawString("buffer.toString()", 5, 15);  }}
    在private String TMP_FILE="C:\\pics\\map20.jpg";这个位置 为什么一定要是绝对路径??? 相对路径不可以吗????
    当我给他相对路径的时候图像就打印不出来!!!
    为什么???