How can I change the IDEA creation folder from TEMP to something else?
I am 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 if it's in file: / C: / Users / Admin / AppData / Local / Temp /
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 )
I am using IntelliJ IDEA 12.
I just want to put my JPEGs in the Exam3 folder instead of the Temp folder. Any ideas?
+3
source to share
1 answer
The workaround for loading a resource using getDocumentBase () allows you to get the URL using the getResource class of the class, which gets the resources relative to the class.
URL base = img.class.getResource("/data/winter.jpg");
Image img = ImageIO.read(base);
where data is the folder in the Exam3 folder in your case that contains this class file.
+1
source to share