Условие - если существует каталог, он должен создавать файлы в этом конкретном каталоге, не создавая новый каталог.
В приведенном ниже коде создается только файл с новым каталогом, но не для существующего каталога. Например, имя каталога будет похоже на "GETDIRECTION"
String PATH = "/remote/dir/server/";
String fileName = PATH.append(id).concat(getTimeStamp()).append(".txt");
String directoryName = PATH.append(this.getClassName());
File file = new File(String.valueOf(fileName));
File directory = new File(String.valueOf(directoryName));
if(!directory.exists()){
directory.mkdir();
if(!file.exists() && !checkEnoughDiskSpace()){
file.getParentFile().mkdir();
file.createNewFile();
}
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(value);
bw.close();