Java Utililty Methods FileWriter Write

List of utility methods to do FileWriter Write

Description

The list of methods to do FileWriter Write are organized into topic(s).

Method

voidsaveFile(String path, String sb)
save File
try {
    FileWriter fstream = new FileWriter(path);
    try (BufferedWriter out = new BufferedWriter(fstream)) {
        out.write(sb);
} catch (Exception e) {
    System.err.println("Error save file: ");
    System.err.println(path);
...
voidsaveFile(String[] lines, String savedName, String extension)
save File
FileWriter fw = new FileWriter("src/main/java/es/uniovi/asw/data/" + savedName + "." + extension);
for (int i = 0; i < lines.length; i++) {
    fw.write(lines[i] + "\n");
fw.close();
voidsaveFileContents(File file, String contents)
save File Contents
try {
    FileWriter fw = new FileWriter(file);
    fw.write(contents);
    fw.close();
} catch (IOException e) {
    throw new RuntimeException(e);
voidsaveFileFromString(File file, String encoding, String content)
writes string to a file
if (content == null) {
    return;
char[] buf = new char[content.length()];
content.getChars(0, buf.length, buf, 0);
OutputStreamWriter f = encoding == null ? new FileWriter(file)
        : new OutputStreamWriter(new FileOutputStream(file), encoding);
try {
...
voidsaveFiles(final List contents, final File outputDirectory, final String outputName, final String fileExtension)
Save file contents in an output directory.
int index;
File directory;
File rooScriptFile;
FileWriter fileWriter;
directory = new File(outputDirectory, outputName);
directory.mkdir();
index = 0;
for (String content : contents) {
...
voidsaveFlows(Map differences, String file)
save Flows
try {
    File f = new File(file);
    if (!f.exists()) {
        f.createNewFile();
    FileWriter fw = new FileWriter(f.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("gene\tflows");
...
voidsaveFormedClustersToFile(Vector names, Collection> clusters, String filename)
Takes a list of clusters (a cluster is a set of integers), and maps the integer IDs to the given list of string entity names.
try {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
    for (Set<Integer> cluster : clusters) {
        boolean first = true;
        for (Integer nameID : cluster) {
            if (!first)
                writer.write(", ");
            writer.write(names.get(nameID));
...
voidsaveGraph(List> graph, String sFileName)
Saves a graph into a csv file in the format of tuples (vertex,edge) for every edge in the graph.
FileWriter writer = new FileWriter(sFileName);
writer.append("Vertex,Edge\n");
for (Integer i = 0; i < graph.size(); i++) {
    for (int j = 0; j < graph.get(i).size(); j++) {
        writer.append(i.toString());
        writer.append(',');
        writer.append(graph.get(i).get(j).toString());
        writer.append('\n');
...
voidsaveIndex(File root_, Hashtable index)
Saves an index (Hashtable) to a file.
saveIndex(root_, "index", index);
voidsaveInputStreamInFile(InputStream stream, FileWriter f)
save Input Stream In File
InputStreamReader st = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(st);
String line;
try {
    while ((line = br.readLine()) != null)
        f.append(line + "\n");
} finally {
    st.close();
...