I need to check if a file exists without allocating memory for it. I just want to check that it exists, I am not interested in getting the content. Is there a simple way to achieve that?
            Asked
            
        
        
            Active
            
        
            Viewed 194 times
        
    -3
            
            
        - 
                    Yes: use a search engine. Next time just try putting your question into google. Surprise. – GhostCat May 21 '18 at 14:17
1 Answers
2
            The java.io.File.exists() method allows you to do just that:
boolean fileExists = new File("path").exists();
Creating a File instance does not read its content on the disk.
 
    
    
        ernest_k
        
- 44,416
- 5
- 53
- 99
- 
                    I forgot to mention that the file is on a remote server. How would look the code in that case? Can I put the remote host in the path string? – Jesus Paradinas May 21 '18 at 18:46
- 
                    1@JesusParadinas Unless the remote server is mapped to a local drive, the File API is pretty much not going to help. What protocol are you using to connect to the remote server? – ernest_k May 21 '18 at 18:52
- 
                    I have been told that the servers are mapped. I am not sure how to connect do you have any suggestion? – Jesus Paradinas May 21 '18 at 19:48
- 
                    1
