Android Text File Write writeToFile(final String path, final String content)

Here you can find the source of writeToFile(final String path, final String content)

Description

Dumps a string into a file.

License

Open Source License

Parameter

Parameter Description
path the path to the file
content the content to write

Exception

Parameter Description
IOException if writting to the file fails

Declaration

public static void writeToFile(final String path, final String content)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

import java.io.RandomAccessFile;

public class Main {
    /**// www.j a  va  2s  .co  m
     * Dumps a string into a file.
     * <p>
     * If the file does not exits it is created. Otherwise, if it already exists it
     * overwritten.
     * 
     * @param path the path to the file
     * @param content the content to write
     * @throws IOException if writting to the file fails
     */
    public static void writeToFile(final String path, final String content)
            throws IOException {
        final File file = new File(path);
        final RandomAccessFile access = new RandomAccessFile(file, "rws");

        try {
            access.writeBytes(content);
        } finally {
            access.close();
        }
    }
}

Related

  1. writeToFile(File target, String s, String charSet)
  2. writeToFile(String content, String filePath)
  3. writeToFile(String sb, String directory, String fileName)
  4. writeToFile(String textToWrite, String fileName)
  5. writeToFile(StringBuffer sb, String directory, String fileName)
  6. saveFile(String content, File file)
  7. writeFileSdcard(File file, String message)
  8. writeFile(String filepath, String text)
  9. writeStringToFile(String text, String filePath)