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 243 views
2 answers 303 views
1 answer 127 views
127 views asked Aug 6, 2023 by avibootz
1 answer 296 views
2 answers 257 views
257 views asked Jun 14, 2016 by avibootz
1 answer 185 views
...