public class DOWNLOADING { public void DOWNLOADING(String FROM, String WHERE) { try { Sardine SARDINE = SardineFactory.begin("login", "password"); InputStream IS = SARDINE.get("https://webdav.yandex.ru" + "/" + FROM); File FILE = new File(WHERE); OutputStream OS = new FileOutputStream(FILE); byte[] BUFFER = new byte[8 * 1024]; int BR; while((BR = IS.read(BUFFER)) != -1) { OS.write(BUFFER, 0, BR); } IS.close(); OS.close(); out.print("\n Skachano\n"); } catch(FileNotFoundException E) { out.print("\n Oshibka\n"); } catch(IOException E) { out.print("\n Oshibka\n"); } } } DOWNLOADING.DOWNLOADING("Путь\Файл.zip", "Путь" + "Файл.zip"); 

In the above code, I download the archive. It is necessary that when downloading (further extraction) the user did not see the archive. I initially tried to set the "hidden" property to the archive, but when downloading to Yandex.Disk and downloading, I don’t know at what stage but the property is not saved. How to make so that the archive would keep the property "hidden" or how to set it when downloading?

For example, the file will download a few minutes and will be visible at the time of downloading and installation. From this you need to somehow get rid of. You can of course shove him far away, but I would just like to hide it as after removing it is removed and no one needs to see it.

  • Yyyy ... hospade - will it ever end or not .... - Barmaley
  • @Barmaley What-what? - aaa
  • just looking at your code you want to cry and cry :) Do not take it to heart)) - Barmaley
  • @Barmaley Tell me then what is wrong, please, I learn and fix it. - aaa

2 answers 2

I did not try it myself, it can work, try:

 Path path = FileSystems.getDefault().getPath("directory", "hidden.txt"); Boolean hidden = path.getAttribute("dos:hidden", LinkOption.NOFOLLOW_LINKS); if (hidden != null && !hidden) { path.setAttribute("dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS); } 

Read more: http://javarevisited.blogspot.com/2012/01/how-to-hide-file-java-program-example.html#ixzz4aedtSbiH

For your case, it may not be appropriate, but if in the path manage to give a link to the file path.setAttribute("dos:hidden", may work ...

Maybe there is something from here: https://stackoverflow.com/questions/1294989/make-a-file-folder-hidden-on-windows-with-java

    In such cases, it is customary to create a temporary file:

     File temp = File.createTempFile("mytempfile", ".tmp"); 

    and write everything there. And then after the end of the download, just rename it to the desired name and that's it.

    PS read about the standards of the Java naming convention - but the truth is my heart bleeds.

    • That is, save the file with the extension .tmp and then rename it to the desired one? - aaa
    • For example, yes ... But you need to create a temporary file to avoid name collisions (all of a sudden it already exists) - Barmaley
    • I have now created a file with the extension .tmp and it is not hidden. - aaa
    • Why do you want to hide it ?! - Barmaley
    • So I originally wrote why in the question. So that the installation process could not be seen, how the files are downloaded and lie in the file system until the program extracts the archive and deletes it. - aaa