Java Utililty Methods Text File Save

List of utility methods to do Text File Save

Description

The list of methods to do Text File Save are organized into topic(s).

Method

voidwriteFile(final String outputDir, final String response, final String fileName)
write File
File dir = new File(outputDir);
dir.mkdirs();
File file = new File(dir, fileName);
final FileWriter writer = new FileWriter(file);
try {
    writer.write(response);
} finally {
    writer.close();
...
voidwriteFile(IFile annotationFile, StringBuffer head, String annotatedSignature, String nextLines, BufferedReader tailReader, IProgressMonitor monitor)
Write back the given annotationFile, with the following content: - head (assumed to include a member and its original signature - annotatedSignature - nextLines (optionally, may be null) - the still unconsumed content of tailReader
head.append(' ').append(annotatedSignature).append('\n');
if (nextLines != null)
    head.append(nextLines).append('\n');
String line;
while ((line = tailReader.readLine()) != null)
    head.append(line).append('\n');
ByteArrayInputStream newContent = new ByteArrayInputStream(head.toString().getBytes("UTF-8")); 
annotationFile.setContents(newContent, IResource.KEEP_HISTORY, monitor);
...
voidwriteFile(IFile file, final InputStream contents, final String charset, IProgressMonitor monitor)
write File
if (!file.exists()) {
    file.create(contents, true, monitor);
} else {
    file.setContents(contents, true, true, monitor);
file.setCharset(charset, monitor);
voidwriteFile(List data, File f)
write File
writeFile(data, f.getAbsolutePath());
voidwriteFile(List fileLines, String pathname)
Writes a List of Strings, each String representing a line in the file, to the file at the specified pathname.
try {
    BufferedWriter writer = new BufferedWriter(new FileWriter(pathname));
    Iterator<String> lineIter = fileLines.iterator();
    if (lineIter.hasNext()) {
        writer.write(lineIter.next());
    while (lineIter.hasNext()) {
        writer.newLine();
...
voidwriteFile(List lines, String filePath)
Write a list of lines to a file.
writeFile(lines, new File(filePath));
voidwriteFile(List strList, String fileFullPath)
write File
try {
    File writeFile = new File(fileFullPath);
    new File(writeFile.getParent()).mkdirs();
    writeFile.createNewFile();
    BufferedWriter out = new BufferedWriter(new FileWriter(writeFile));
    for (String str : strList) {
        out.write(str + LINE_SEPARATOR);
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
booleanwriteFile(List txtList, String MyFilePath)
write File
boolean tag = true;
try {
    FileWriter writer = new FileWriter(MyFilePath);
    BufferedWriter bufWriter = new BufferedWriter(writer);
    for (String txtData : txtList) {
        bufWriter.write(txtData);
        bufWriter.newLine();
    bufWriter.close();
    writer.close();
} catch (Exception e) {
    tag = false;
    e.printStackTrace();
return tag;
StringwriteFile(String file, String content)
write File
File log = new File(file);
FileOutputStream fos;
BufferedOutputStream bos;
try {
    fos = new FileOutputStream(log);
    bos = new BufferedOutputStream(fos);
    bos.write(content.getBytes("UTF-8"));
    bos.close();
...
intwriteFile(String file, String text)
write File
return writeFile(file, text, null);