简体   繁体   English

ImageIO无法读取输入文件(科特琳)

[英]ImageIO Can't read input file (Kotlin)

Hi i using kotlin to make a discord bot, I have a PNG called sam.png but i try to insert and get this error: 嗨,我使用Kotlin制作了不和谐的机器人,我有一个名为sam.png的PNG,但是我尝试插入并得到此错误:

[23:18:38] [Fatal] [JDA]: javax.imageio.IIOException: Can't read input file! [23:18:38] [致命] [JDA]:javax.imageio.IIOException:无法读取输入文件!

override fun run(ev: MessageReceivedEvent) {
    var selaSam: Image = ImageIO.read(File("/sam.png"))
    var image = LikeUtils.downloadImage(LikeUtils.getUserHandle(ev).getEffectiveAvatarUrl())

    image.graphics.drawImage(selaSam, 200, 200, null)

    LikeUtils.sendFile(image, "/resources/sam.png", null)
}

The path /sam.png means that the file is available in the root path (not the workiing path of your project but the root path of your system). 路径/sam.png表示该文件在根路径中可用(不是项目的工作路径,而是系统的根路径)。 I doubt that this is the case. 我怀疑情况是否如此。

I guess you want that path: ./sam.png . 我猜你想要那个路径: ./sam.png Would be better to check if the file exists with 最好检查文件是否存在

override fun run(ev: MessageReceivedEvent) {
    val imagePath = "/sam.png"
    val image = File(imagePath)
    if (!image.exists()) throw RuntimeException("Image $imagePath not found")
    if (image.isDirectory) throw RuntimeException("Image $imagePath is a directory")

    var selaSam: Image = ImageIO.read(image)
    var image = LikeUtils.downloadImage(LikeUtils.getUserHandle(ev).getEffectiveAvatarUrl())

    image.graphics.drawImage(selaSam, 200, 200, null)

    LikeUtils.sendFile(image, "/resources/sam.png", null)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM