Q:

how to create file in java in resources directory

I have a maven project and need to write JSON objects in file.json that should be located in 
src/main/resources/
But before I need to check if file exists. If not than create it.
public static void writeMenuJSon(String jsonParamIn) {
    JsonParser parser = new JsonParser();
    JsonObject modulJson = parser.parse(jsonParamIn).getAsJsonObject();

    //TODO check if file exists and create file if not

   code here ...

   // write to file JSON object
   try (Writer writer = new FileWriter("path to file")){

        Gson gson = new GsonBuilder().create();
        gson.toJson(modulJson, writer);

    } catch (IOException e) {
        e.printStackTrace();
    }

}

A:

Something is totally wrong if you are creating dynamically file in src/main/resources This is only going to work in your development environment. When you deploy your code using Jar or War there won't be this directory on file system. It will be contained within Jar / War or other packaging.
If you understand above and still want to do it. Go related to your current working directory to create file, Usually the working directory when you launch your Main from IDE is setup to root of project so create a file at
src/main/resources/foo.txt
will do it. Alternatively you can figure out your current working directory from your IDE launcher or at runtime using
System.getProperty("user.dir");

