A
A
Andrey Unger2015-05-22 12:26:56
Java
Andrey Unger, 2015-05-22 12:26:56

Why can't copy the file?

There is the following piece of code.

final File myself = new File(new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile()).getParentFile(), "Consultant.jar");
    final File tmp = File.createTempFile("Chat", ".tmp");

    try(
    final ReadableByteChannel rbc = Channels.newChannel(new URL(url).openStream())
    )

    {
        try (final FileOutputStream fos = new FileOutputStream(tmp)) {
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            fos.flush();
        }
    }

    if(!tmp.renameTo(myself))

    {
        try {
            Files.move(tmp.toPath(), myself.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("Cant rename tmp-download version '" + tmp.getAbsolutePath() + "' to exec-binary '" + myself.getAbsolutePath() + "'\r\n" + e.getMessage());

        }
    }

But for some reason it doesn't work. I have been struggling with the problem for a long time, but I only see the following error:
java.lang.Exception: Cant rename tmp-download version 'C:\Users\Cobalt\AppData\Local\Temp\Chat6072918692286185513.tmp' to exec-binary 'C: \Program%20Files\Consultant\app\Consultant.jar'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
poisonGreen, 2015-05-22
@poisonGreen

Copy, not move gives?
If it does, then most likely some process is holding the file.
If it does not, then something with the rights.

N
Nikolai, 2015-05-22
@j_wayne

And what is the original exception on stdout?
Offhand - %20 instead of a space is not pleasant.

A
Andrey Unger, 2015-05-22
@Cobalt

Yes, the fact of the matter is that apart from this, nothing else is written to the log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question