/** Writes the specified string to the file using the default charset. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public void writeString (String string, boolean append) { writeString(string, append, null); }
/** Writes the specified string to the file using the default charset. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public void writeString (String string, boolean append) { writeString(string, append, null); }
public static void main (String[] args) { FileHandle file = new FileHandle(args[0]); StringBuffer list = new StringBuffer(); args[0] = args[0].replace("\\", "/"); if (!args[0].endsWith("/")) args[0] = args[0] + "/"; traverse(file, args[0], list); new FileHandle(args[0] + "/assets.txt").writeString(list.toString(), false); }
@Override protected Shader createShader (Renderable renderable) { if (config.vertexShader != null && config.fragmentShader != null && tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) { String prefix = DefaultShader.createPrefix(renderable, config); Gdx.files.absolute(tempFolder).child(name + ".vertex.glsl").writeString(prefix + config.vertexShader, false); Gdx.files.absolute(tempFolder).child(name + ".fragment.glsl").writeString(prefix + config.fragmentShader, false); } BaseShader result = new MultiPassShader(renderable, config); if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(result.program.getLog(), false); return result; } }
if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset);
if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset);
@Override public Shader getShader (Renderable renderable) { try { return super.getShader(renderable); } catch (Throwable e) { if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(e.getMessage(), false); if (!revert()) { Gdx.app.error("ShaderCollectionTest", e.getMessage()); throw new GdxRuntimeException("Error creating shader, cannot revert to default shader", e); } error = true; Gdx.app.error("ShaderTest", "Could not create shader, reverted to default shader.", e); return super.getShader(renderable); } }
new FileHandle(new File("jni/Application.mk")).writeString("\nAPP_STL := stlport_static\n", true);
new FileHandle(new File("jni/Application.mk")).writeString("\nAPP_STL := stlport_static\n", true);
/** Writes the specified string to the file using the default charset. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * {@link FileType#Internal} file, or if it could not be written. */ public void writeString (String string, boolean append) { writeString(string, append, null); }
FileHandle file = Gdx.files.local(filename); file.writeString(stringToWrite, false);
FileHandle file = Gdx.files.local("scores.json"); file.writeString(score, true); // True means append, false means overwrite.
FileHandle file = Gdx.files.local("myfile.txt"); file.writeString("My god, it's full of stars", false);
String mapOfTheDay = ...; FileHandle mapOfTheDayFile = Gdx.files.external("mygame/mapoftheday.tmx"); mapOfTheDayFile.writeString(mapOfTheDay, false); TiledMap tileMap = new TmxMapLoader(new ExternalFileHandleResolver()).load("mygame/mapoftheday.tmx");
public static void save () { try { FileHandle filehandle = Gdx.files.external(file); filehandle.writeString(Boolean.toString(soundEnabled)+"\n", false); for (int i = 0; i < 5; i++) { filehandle.writeString(Integer.toString(highscores[i])+"\n", true); } } catch (Throwable e) { } }
//Read FileHandle file = Gdx.files.internal("savefile/highscore.txt"); if(file.exists()){ highscore = Float.valueOf(file.readString()); } //Write if(currentscore > highscore){ file.writeString(Float.toString(currentscore ),false); }
/** * @param object The object to serialize * @param knownType May be null if the type is unknown. * @param elementType May be null if the type is unknown. * @param file A LibGDX FileHandle that can be written to; overwrites, does not append */ @Override public void toJson (Object object, Class knownType, Class elementType, FileHandle file) { try { file.writeString(this.toJson(object, knownType, elementType), false, "UTF-8"); } catch (Exception ex) { throw new SerializationException("Error writing file: " + file, ex); } }
GameResults results = new GameResults(); results.setWins(winstring); Json json = new Json(); FileHandle scores = Gdx.files.local("Score"); scores.writeString(json.toJson(results), false);
@Override public void writeString(String content, String... filepath) throws PlayerDataException { if (filepath.length == 0) { throw new PlayerDataException("No file path specified"); } try { FileHandle file = resolve(filepath); file.writeString(content, false); } catch (Exception e) { throw new PlayerDataException(e); } }
@Override public <T> void writeJson(T object, String... filepath) throws PlayerDataException { if (filepath.length == 0) { throw new PlayerDataException("No file path specified"); } try { resolve(filepath).writeString(Mdx.json.toJson(object), false); } catch (SerializationException e) { throw new PlayerDataException(e); } }