How to get the parent directory of a specific directory 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\\mysql\\data");
 
            String sParentDirectory = file.getParent();
 
            System.out.println(sParentDirectory);
 
        } catch (Exception e) {
            System.out.print(e);
        }
    }
}
 
 
/*
         
run:
   
d:\xampp\mysql
 
 */

 



answered Nov 17, 2016 by avibootz

Related questions

1 answer 236 views
2 answers 294 views
1 answer 116 views
116 views asked Aug 6, 2023 by avibootz
1 answer 287 views
2 answers 247 views
247 views asked Jun 14, 2016 by avibootz
1 answer 177 views
...