How to get the parent directory of a specific file in Java

1 Answer

0 votes
package javaapplication1;
 
import java.io.File;
import java.io.IOException;
 
public class JavaApplication1 {
 
    public static void main(String[] args) throws IOException {
 
        try {
 
            File file = new File("d:\\xampp\\htdocs\\seek4info.com");
 
            String sParentDirectory = file.getParent();
 
            System.out.println(sParentDirectory);
 
        } catch (Exception e) {
            System.out.print(e);
        }
    }
}
 
 
/*
         
run:
   
d:\xampp\htdocs
 
 */

 



answered Nov 17, 2016 by avibootz

Related questions

2 answers 297 views
1 answer 212 views
1 answer 119 views
119 views asked Aug 6, 2023 by avibootz
1 answer 288 views
2 answers 249 views
249 views asked Jun 14, 2016 by avibootz
1 answer 182 views
...