Q: Java creating a file in a certain directory How do I get a json file I am creating to go into another directory. I am using a method that gives a file name and use this code to create it, its not the full code but Im pretty sure this is the only part I need to modify.
FileInputStream in = new FileInputStream(fileName);
     JSONObject obj = new JSONObject(new JSONTokener(in));

right now it puts it in a directory but I want to put it in a folder in that directory.
this also does not work
FileInputStream in = new FileInputStream("/A/Ab/src/serv"+fileName);

///////////////////////////
File cDir = new File("");
FileInputStream in = new FileInputStream(cDir.getAbsoluteFile() +fileName);


A: Try this:
File dir = new File("/A/Ab/src/serv");
if (!dir.exists()) dir.mkdirs();

then:
FileInputStream in = new FileInputStream("/A/Ab/src/serv/" + filename);`enter code here`

If the directory already exists and you just want to create a new file, then simply do:
 FileInputStream in = new FileInputStream(new File("/A/Ab/src/serv/" + filename))

