### Question:
ParseFileUtils { public static void writeJSONObjectToFile(File file, JSONObject json) throws IOException { ParseFileUtils.writeByteArrayToFile(file, json.toString().getBytes(Charset.forName("UTF-8"))); }  static byte[] readFileToByteArray(File file); static FileInputStream openInputStream(File file); static void writeByteArrayToFile(File file, byte[] data); static FileOutputStream openOutputStream(File file); static void moveFile(final File srcFile, final File destFile); static void copyFile(final File srcFile, final File destFile); static void copyFile(final File srcFile, final File destFile,
                              final boolean preserveFileDate); static void deleteDirectory(final File directory); static boolean deleteQuietly(final File file); static void cleanDirectory(final File directory); static void forceDelete(final File file); static boolean isSymlink(final File file); static String readFileToString(File file, Charset encoding); static String readFileToString(File file, String encoding); static void writeStringToFile(File file, String string, Charset encoding); static void writeStringToFile(File file, String string, String encoding); static JSONObject readFileToJSONObject(File file); static void writeJSONObjectToFile(File file, JSONObject json); static final long ONE_KB; static final long ONE_MB; }### Answer:
@Test public void testWriteJSONObjectToFile() throws Exception { File file = temporaryFolder.newFile("file.txt"); ParseFileUtils.writeJSONObjectToFile(file, new JSONObject(TEST_JSON)); InputStream in = null; String content = null; try { in = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream(); ParseIOUtils.copy(in, out); content = new String(out.toByteArray()); } finally { ParseIOUtils.closeQuietly(in); } JSONObject json = new JSONObject(content); assertNotNull(json); assertEquals("bar", json.getString("foo")); }