First use a StringBuilder to create your String:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < movementArray.length; i++)
{
sb.append(movementArray[i]);
}
setContents(new File("your path here"), sb.toString());
The setContents(File aFile, String aContents)
method will set a string content in a file.
public static void setContents(File aFile, String aContents)
throws FileNotFoundException, IOException {
if (aFile == null) {
throw new IllegalArgumentException("File should not be null.");
}
if (!aFile.exists()) {
throw new FileNotFoundException("File does not exist: " + aFile);
}
if (!aFile.isFile()) {
throw new IllegalArgumentException("Should not be a directory: " + aFile);
}
if (!aFile.canWrite()) {
throw new IllegalArgumentException("File cannot be written: " + aFile);
}
//declared here only to make visible to finally clause; generic reference
Writer output = null;
try {
//use buffering
//FileWriter always assumes default encoding is OK!
output = new BufferedWriter(new FileWriter(aFile));
output.write(aContents);
} finally {
//flush and close both "output" and its underlying FileWriter
if (output != null) {
output.close();
}
}
}