Este codigo grava no final mas gostaria de gravar no inicio, se possível
public static void main(String[] args) {
escrever("C:\\Users\\joao\\Desktop\\Arquivos Java/arquivoPing.txt", "Olá Arquivo2");
}
public static void escrever(String path, String texto) {
try {
// O parametro é que indica se deve sobrescrever ou continua no
// arquivo.
FileWriter fw = new FileWriter(path, true);
BufferedWriter conexao = new BufferedWriter(fw);
conexao.write("\n"+texto);
conexao.newLine();
conexao.close();
} catch (IOException e) {
System.out.println(e);
}
}