title: Save file in specific folder with Google Drive SDK Java
body: <p>Since I was not allowed to ask in the relevant thread <a href="https://stackoverflow.com/questions/14422661/save-file-in-specific-folder-with-google-drive-sdk/21357711#21357711">Save file in specific folder with Google Drive SDK</a></p>
  
  <pre><code>File body = new File();  
  body.setTitle(fileContent.getName());
  body.setMimeType("text/plain");
  body.setParents(Arrays.asList(new File.ParentReference().setId(parentId));  
  File file = service.files().insert(body, textContent).execute();
  </code></pre>
  
  <p>The File. ".ParentReference()" is giving me a problem what am I missing?</p>
  
  <p>My current code which will not load into folder XXX</p>
  
  <pre><code>      HttpTransport httpTransport = new NetHttpTransport();
          JsonFactory jsonFactory = new JacksonFactory();
  
          GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
          GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);
  
  //      Create a new authorized API client
          Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build();
  
          ParentReference newParent = new ParentReference();
          newParent.setId("XXX");
  
  //      Insert a file  
          File body = new File();
          body.setTitle(fileID);
          body.setDescription(fileID);
          body.setMimeType("text/plain");
          body.setParents(Arrays.asList(newParent));
  
          List&lt;File&gt; files = service.files().list().setQ("mimeType = 'application/vnd.google-apps.folder'").execute().getItems();
          for (File f : files) {
              System.out.println(f.getTitle() + ", " + f.getMimeType());
          }
  
          java.io.File fileContent = new java.io.File(fileID);
          FileContent mediaContent = new FileContent("text/plain", fileContent);
  
          File file = service.files().insert(body, mediaContent).execute();
          System.out.println("File ID: " + file.getId());
  </code></pre>