1
The method below generates a txt containing certain information:
public static void gravarIp(String ip)
{
try {
File arquivo = new File("ip.txt");
FileOutputStream fos = new FileOutputStream(arquivo);
String texto = ip;
fos.write(texto.getBytes());
fos.close();
atualizarPortal(ip);
}
catch (IOException e)
{
e.printStackTrace();
}
}
However, this txt is being generated at the place where the instruction is executed:
c:\>java -cp c:\users\fabio\desktop EnviarIp
That is, if the above statement is executed and I am at the root of c: txt will be generated there. How do I generate txt on the same root as the Send file without specifying the absolute path in the source code?
First, what is it
EnviarIp? Nothing in the code indicates this. Following, because you cannot specify the absolute path?– Maniero
I only published part of the code, "Enviar ip" is the java class, as it should already be known to run a java code we can use the java command line -cp path_do_file File. I cannot inform the way because it will be relative according to user profile and other factors.
– Fábio Jânio