List of utility methods to do Text File Write
void | writeTextToFile(String file, String text) Simple method to write text to a file try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(text); writer.close(); } catch (IOException e) { e.printStackTrace(); |
void | writeToFile(File file, String content) write To File try { FileWriter fstream = new FileWriter(file, true); BufferedWriter out = new BufferedWriter(fstream); out.write(content); out.close(); } catch (IOException e) { throw new RuntimeException(e); |
void | writeToFile(File target, String s, String charSet) write To File FileOutputStream fos = new FileOutputStream(target);
fos.write(s.getBytes(charSet));
fos.close();
|
void | writeToFile(String content, String filePath) write To File File file = createFile(filePath); FileWriter fw = new FileWriter(file, true); PrintWriter pWriter = new PrintWriter(new BufferedWriter(fw)); pWriter.println(content); pWriter.close(); fw.close(); |
void | writeToFile(String sb, String directory, String fileName) write To File File dir = new File(directory); dir.mkdirs(); if (!directory.endsWith("/")) { directory = directory + "/"; File out = new File(directory + fileName); System.out.println(directory + fileName); try { ... |
String | writeToFile(String textToWrite, String fileName) writes the contents of textToWrite to a file on the local filesystem identified by fileName. File outFile = new File(fileName); try { if (!outFile.exists()) { outFile.createNewFile(); FileWriter out = new FileWriter(outFile, true); out.write(textToWrite); out.close(); ... |
void | writeToFile(StringBuffer sb, String directory, String fileName) write To File writeToFile(sb.toString(), directory, fileName); |
void | writeToFile(final String path, final String content) Dumps a string into a file. final File file = new File(path); final RandomAccessFile access = new RandomAccessFile(file, "rws"); try { access.writeBytes(content); } finally { access.close(); |
void | saveFile(String content, File file) Saves the content String to the specified file. BufferedWriter writer = Files.newBufferedWriter(file.toPath(), CHARSET); writer.write(content, 0, content.length()); writer.close(); |
void | writeFileSdcard(File file, String message) write File Sdcard FileOutputStream fout = new FileOutputStream(file); byte[] bytes = message.getBytes("UTF-8"); fout.write(bytes); fout.flush(); fout.close(); |