简体   繁体   English

如何将IDEA的构建文件夹从TEMP更改为其他内容?

[英]How do I change IDEA's build folder from TEMP to something else?

Im trying to run: 我试图运行:

import java.applet.Applet;
import java.awt.*;
import java.net.URL;

public class img extends Applet
{
    private Image img;
    public void init()
    {
        img = null;
    }
    public void loadImage()
    {
        try
        {
            img = getImage(getCodeBase(), "winter.jpg");
            System.out.println(img);
            System.out.println(prepareImage(img, 300, 400, this));
        }
        catch(Exception e){}

        System.out.println(getDocumentBase());
    }
    public void paint(Graphics g)
    {
        if (img == null)
            loadImage();
        g.drawImage(img, 0, 0, this);
    }
}

But it doesn't find winter.jpg unless its in: file:/C:/Users/Admin/AppData/Local/Temp/ 但它找不到winter.jpg,除非它在:file:/ C:/ Users / Admin / AppData / Local / Temp /

System.out.println(getDocumentBase()); 的System.out.println(getDocumentBase()); returns: file:/C:/Users/Admin/AppData/Local/Temp/AppletPage1228891259548967526.html Instead of: C:/Users/Admin/Dropbox/dev/idea/Exam3/out/production/Exam3/ (where the .class files are located) 返回:file:/ C:/Users/Admin/AppData/Local/Temp/AppletPage1228891259548967526.html而不是:C:/ Users / Admin / Dropbox / dev / idea / Exam3 / out / production / Exam3 /(其中.class文件位于)

I'm using IntelliJ IDEA 12. 我正在使用IntelliJ IDEA 12。

I simply want to put my JPEGs in the Exam3 folder instead of the Temp folder. 我只想将我的JPEG放在Exam3文件夹而不是Temp文件夹中。 Any ideas? 有任何想法吗?

A workaround for loading the resource using getDocumentBase() you can get the URL by using the getResource of class which gets the resources relative to the class. 使用getDocumentBase()加载资源的变通方法,您可以使用类的getResource获取URL,该类获取相对于类的资源。

URL base = img.class.getResource("/data/winter.jpg");
Image img = ImageIO.read(base);

where data is a folder in the Exam3 folder in your case which contains this class file. 其中data是包含此类文件的Cases3文件夹中的文件夹。

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

相关问题 如何将文件夹复制到temp目录? - How do I copy a folder into the temp directory? 如何使Selenium Webdriver等待元素将其属性更改为Java中的其他内容 - How do I make Selenium webdriver to wait for an element to change its attribute to something else in Java 如何在Eclipse中将'// TODO自动生成的方法存根'更改为其他内容? - How do I change '// TODO Auto-generated method stub' to something else in Eclipse? 如何在 IntelliJ IDEA 中默认将文件夹指定为源文件夹? - How do I designate a folder as a Source folder by default in IntelliJ IDEA? 我如何将JTextArea字符串更改为其他内容 - How can i change the JTextArea string to something else 如何还原Idea中模块的父文件夹 - How do I restore parent folder of modules in Idea 我如何比较已打印的内容? - How do I compare something to something that's already been printed? 我如何将自己构建的GUI与其他地方的功能一起使用? - How do i use a gui i build together with functions from somewhere else? JPA Hibernate意外地获取@OneToOne映射实体的记录,我应该将映射更改为@ManyToOne还是做其他事情? - JPA Hibernate unexpectedly fetches records of @OneToOne mapped entity, should I change mapping to @ManyToOne or do something else? 如何进行if-if测试字符串中的内容并删除或更改内容 - How to make an if else-if test for something in a string and delete or change something
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM