Java Code Examples for com.badlogic.gdx.files.FileHandle#writer()

The following examples show how to use com.badlogic.gdx.files.FileHandle#writer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Settings.java    From Cubes with MIT License 6 votes vote down vote up
public static boolean write() {
  FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
  JsonObject json = new JsonObject();
  for (Map.Entry<String, Setting> entry : settings.entrySet()) {
    json.set(entry.getKey(), entry.getValue().toJson());
  }
  try {
    Writer writer = fileHandle.writer(false);
    json.writeTo(writer, WriterConfig.PRETTY_PRINT);
    writer.close();
  } catch (Exception e) {
    Log.error("Failed to write settings", e);
    fileHandle.delete();
    return false;
  }
  return true;
}
 
Example 2
Source File: LmlUtils.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public static void saveDtdSchema(final LmlParser lmlParser, final FileHandle file) {
    try {
        final Writer appendable = file.writer(false, "UTF-8");
        final boolean strict = lmlParser.isStrict();
        lmlParser.setStrict(false); // Temporary setting to non-strict to generate as much tags as possible.
        Dtd.saveSchema(lmlParser, appendable);
        appendable.close();
        lmlParser.setStrict(strict);
    } catch (final Exception exception) {
        throw new GdxRuntimeException("Unable to save DTD schema.", exception);
    }
}
 
Example 3
Source File: LmlUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public static void saveDtdSchema(final LmlParser lmlParser, final FileHandle file) {
    try {
        final Writer appendable = file.writer(false, "UTF-8");
        final boolean strict = lmlParser.isStrict();
        lmlParser.setStrict(false); // Temporary setting to non-strict to generate as much tags as possible.
        Dtd.saveSchema(lmlParser, appendable);
        appendable.close();
        lmlParser.setStrict(strict);
    } catch (final Exception exception) {
        throw new GdxRuntimeException("Unable to save DTD schema.", exception);
    }
}
 
Example 4
Source File: ClassFinderCache.java    From libgdx-snippets with MIT License 4 votes vote down vote up
public void writeToFile(FileHandle file) throws IOException {

		try (Writer writer = file.writer(false, "UTF-8")) {

			for (ObjectMap.Entry<String, Array<String>> group : classNames) {

				writer.append(':').append(group.key).append('\n');

				for (String name : group.value) {
					writer.append(name).append('\n');
				}
			}

			writer.flush();
		}
	}