Java IO 无法读取 Java Applet 下的输入文件

标签 java ioexception

Java 在读取图像文件时抛出异常:

javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at UI.readMatrix(UI.java:27)
at MazeViewControl.init(MazeViewControl.java:45)
at sun.applet.AppletPanel.run(AppletPanel.java:424)
at java.lang.Thread.run(Thread.java:680)

图像 IO 在作为 Java 应用程序运行时工作正常:

public class MazeViewControl extends JApplet {
UI ui;
MazeView view;
Maze maze;
int theme;
int option;
String filename="src/maze0.bmp";

public  void init() {
    ui=new UI();
    maze=new Maze();
        try {
            ui.readMatrix("src/maze0.bmp", maze, 1, 0, 0,0,319,239);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

public class UI {
    public UI(){
        return;
    }
/**
   * read and construct the map from a txt file
   * @param filename
   * @throws IOException 
   */
    public void readMatrix(String filename, Maze m, int theme, int option, int sx, int sy, int ex, int ey) throws IOException{
        /* pre-read the file*/

        //Create file for the source
        File input = new File(filename);
        int rows=0;
        int columns=0;
        //Read the file to a BufferedImage
        // Surround this with try/catch or have your method
        // throw an exception
        System.out.println(filename);
        BufferedImage image = ImageIO.read(input);

最佳答案

这就是它应该如何工作的。小程序无法访问本地文件。您可能需要一个具有文件系统访问权限的签名小程序。

关于Java IO 无法读取 Java Applet 下的输入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12628639/

相关文章:

java - Tomcat & Maven : "Publishing failed with multiple errors Error reading file"

java - 如何根据特定顺序对 hibernate 结果进行排序

java IO异常: Stream Closed

java - 如何通过在 android 中启动一个新的 Activity 来处理 IOException

c# - 我如何判断 IOException 是否是由另一个进程使用该文件这一事实引起的?

java - CannotResolveClassException : com. blazemeter.jmeter.RandomCSVDataSetConfig

java - cordova/Mobile First 应用程序中的“主要版本 51 比 5 更新”

java - HttpUtils.httpConnection() 被拒绝

java - 什么是 java.io.IOException : invalid header field?

scala - Spark 错误 : "ERROR Utils: Exception while deleting Spark temp dir:"