I've created a code that uses a file that is located in a certain directory (resources). When I squeeze this code through eclipse, this directory is found and all code actions are done. However, by generating a .jar
of this code, it does not find the specified directory. I need some way to access this directory through the .jar
file.
Here's 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 "squeeze" through .jar
the error appears:
"src / resources / StatusTestesGPES_template.xls (The system can not find the path)"