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 329 views
2 answers 428 views
1 answer 212 views
212 views asked Aug 6, 2023 by avibootz
1 answer 367 views
2 answers 364 views
364 views asked Jun 14, 2016 by avibootz
1 answer 268 views
...