0
I created a code that uses a file that is located in a given directory (Resources). When I run this code by eclipse, this directory is found and all code actions are done. However, when generating a .jar
of this code, it does not find the specified directory. I need to somehow access this directory by the file .jar
.
Follow part of my code:
teste = Json.criarJson(teste, json);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
CopyTemplate.copyfile("src/resources/StatusTestesGPES_template.xls", "src/resources/StatusTestesGPES_"+ dateFormat.format(date)+".xls", teste);
Copyfile:
public static void copyfile(String ORIcaminho, String DEScaminho, Test[] teste) throws InvalidFormatException, ParseException
{
try
{
File origem = new File(ORIcaminho);
File destino = new File(DEScaminho);
InputStream in = new FileInputStream(origem);
//For Overwrite the file.
OutputStream out = new FileOutputStream(destino);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
in.close();
out.close();
}
catch(FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, e.getMessage() , "Erro", JOptionPane.ERROR_MESSAGE);
throw new RuntimeException(e);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
throw new RuntimeException(e);
}
}
When I "spin" by .jar
error appears:
"src/Resources/Statustesgpes_template.xls (sist. cannot find the path)"
You want to access compiled files inside the jar, that’s it?
– user28595
that’s right... "Statustesgpes_template.xls" is one of those files for example
– Mari Teixeira
You can’t move files inside the jar itself, you’d have to recreate it for that.
– user28595
What do you mean? I don’t understand
– Mari Teixeira
You are trying to move files inside the jar itself, this is not possible without "repacking" it, ie you would need to create the jar again.
– user28595
I am not trying to move. I read from the "template" file and create a new file
– Mari Teixeira