I want to create Java program that creates certain HTML files and since they all contain some images, program should also copy those images to the user.dir, where HTML files are created. I have those images in package "resources", code is in package "code". How do I make that happend?
+2
A:
Basically, you will need a list of the resource files that you wish to copy. Them you use
public class CopyUtil {
public void doTheCopy( List<String> resourceNames ) {
for ( String resource : resourceNames ) {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource);
FileOutputStream fos =
new FileOutputStream( new File(System.getProperty("user.dir"), resource));
byte[] buffer = new byte[1024];
int read = -1;
while( (read = is.read(buffer)) != -1 ) {
fos.write( buffer,0,read);
}
fos.flush();
fos.close();
}
}
}
Clint
2010-01-19 17:36:36
This should be a static method.
Jherico
2010-01-19 17:50:33