Java Text File Write nio writeArray2File(File file, Object[] objects, String code)

Here you can find the source of writeArray2File(File file, Object[] objects, String code)

Description

write Array File

License

Apache License

Declaration

static void writeArray2File(File file, Object[] objects, String code) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.nio.charset.Charset;

public class Main {
    static void writeArray2File(File file, Object[] objects, String code) {
        try {/*from   w w w  . j  av  a 2  s .  c o  m*/
            String myCode = code != null && !"".equals(code) ? code : Charset.defaultCharset().name();
            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), myCode);
            BufferedWriter writer = new BufferedWriter(out);
            for (int i = 0; i < objects.length; i++) {
                writer.write(objects[i].toString());
                if (i < objects.length - 1)
                    writer.newLine();
            }

            writer.flush();
            writer.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. write(String content, String file)
  2. write(String location, String content)
  3. write(String msg)
  4. writeAllLines(File file, List list)
  5. writeAllText(File file, String contents)
  6. writeAscii(CharSequence ascii, OutputStream os)
  7. writeContent(File file, String content)
  8. writeContent(File file, String content)
  9. writeData(String address, BigInteger toWrite)