List of utility methods to do Text File Write by Charset
void | writer(String path, String content, String charset) writer OutputStream out = fileOut(path, false); out.write(content.getBytes(charset)); close(out); |
BufferedWriter | writerBuffered(final File file, final Charset charset) Open a buffered Writer , equivalent to: new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); return writer; |
String | writeStreamToString(InputStream is, String charsetName) write Stream To String return writeStreamToString(is, Charset.forName(charsetName));
|
void | writeString(OutputStream os, String string, CharsetEncoder encoder) write String OutputStreamWriter writer = new OutputStreamWriter(os, encoder);
writer.write(string);
writer.flush();
|
void | writeString(OutputStream out, String charset, String value) Convert a \n string to a platform encoding. writeString(out, Charset.forName(charset), value); |
void | writeStringToFile(File file, String s, String charset) Writes string to file. writeStringToFile(file, s, charset, false); |
void | writeStringToFile(String fileContent, String filePath, String charset) write String To File File cacheFile = new File(filePath); File fileContents; if (cacheFile.exists()) { try { cacheFile.delete(); } catch (Exception var25) { ; } else { fileContents = cacheFile.getParentFile(); if (!fileContents.exists()) { fileContents.mkdirs(); try { cacheFile.createNewFile(); } catch (Exception var24) { ; cacheFile = new File(filePath); if (cacheFile.exists()) { byte[] fileContentsBytes; if (null != charset && !charset.trim().isEmpty()) { fileContentsBytes = fileContent.getBytes(charset); } else { fileContentsBytes = fileContent.getBytes(); ByteBuffer buf = ByteBuffer.wrap(fileContentsBytes); FileOutputStream fout = null; FileChannel outc = null; try { fout = new FileOutputStream(filePath); outc = fout.getChannel(); outc.write(buf); } catch (FileNotFoundException var22) { throw var22; } catch (IOException var23) { throw var23; } finally { if (fout != null) { try { fout.close(); } catch (IOException var21) { ; if (outc != null) { try { outc.close(); } catch (IOException var20) { ; |
void | writeStringToFile(String filename, String contents, Charset encoding) write String To File try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), encoding)) { out.write(contents); |
void | writeStringToFile(String fileName, String str, String charset) Writes a string to a file, replacing any existing contents, using the platform's default character set. File file = new File(fileName); if (!Charset.isSupported(charset)) { throw new UnsupportedEncodingException(charset); try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), charset)) { writer.write(str); |
void | writeStringToStream(String string, OutputStream stream, Charset charset) Writes given string to given stream, using given charset OutputStreamWriter osw = new OutputStreamWriter(stream, charset); try { osw.append(string); osw.flush(); } finally { osw.close(); |