小程序:无法读取图像文件

Applet: Unable to read image file

本文关键字:读取 图像 文件 程序      更新时间:2023-09-26

我在调用ImageIO.read来读取文件时遇到了一些问题。这个小程序嵌入到HTML页面上,我正在使用Javascript返回一个字符串("second")。在调用 ImageIO.read 之前,可以显示字符串"second"。但是,在调用ImageIO.read后,无法显示"second"。我希望在读取图像文件后将"秒"返回给用户。

非常感谢任何帮助。谢谢。

.HTML

<html>
<body>
    <script language = "JavaScript">
    function bing()
    {
        alert(document.xyz2.Test());
    }
    </script>
    <input type="button" value="Value" onclick="bing()"/>
    <applet name="xyz2" code="xyz2.class" width=100 height=100>
    </applet>
</body>
</html>

小程序代码

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JApplet;

public class xyz2 extends JApplet {
   public String s="first";
   public BufferedImage bf;
   public void init(){

   }
   public String Test() throws IOException{
       bf = ImageIO.read(new File("c:''rose.jpg"));
       s = "second";
       return s;
   }
}

从文件系统读取映像时可能会遇到异常。小程序需要签名才能触摸这些文件。

一些选择:

  • 为小程序签名
  • 从您访问小程序的网页中读取图像
  • 在小程序资源中嵌入图像