Example usage for java.io FileWriter close

List of usage examples for java.io FileWriter close

Introduction

In this page you can find the example usage for java.io FileWriter close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:com.mycompany.horus.Teste.java

public static void stringToDom(String xmlSource) throws IOException {
    java.io.FileWriter fw = new java.io.FileWriter("teste.xml");
    fw.write(xmlSource);//from  ww  w.j  a  v a 2s.co m
    fw.close();
}

From source file:test.gov.nih.nci.system.web.client.ComputerClient.java

private static File marshall(Computer computer) throws IOException, XMLUtilityException {
    String namespacePrefix = "gme://caCORE.caCORE/3.2/";
    String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional";
    //Marshaller marshaller = new JAXBMarshaller(includeXmlDeclaration,jaxbContextName);  // Use this constructor if you plan to pass the namespace prefix with each call instead
    Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix);
    Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
    XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller);
    File myFile = new File("Computer.xml");
    FileWriter myWriter = new FileWriter(myFile);
    myUtil.toXML(computer, myWriter);/* ww w.  ja v a  2 s . com*/
    myWriter.close();
    return myFile;
}

From source file:Main.java

public static File saveText(String text) throws IOException {
    File f;/*w ww.j  a va2  s .c o m*/
    String filename;
    if (!isExternalStorageWritable())
        throw new IOException("Storage not available");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    filename = dateFormat.format(new Date());

    f = new File(getAlbumStorageDir(FOLDER_NAME), "Message " + filename + ".txt");
    FileWriter fw = new FileWriter(f);
    fw.write(text);
    fw.close();
    return f;
}

From source file:test.gov.nih.nci.system.web.client.OrderLineCreateClient.java

private static File marshall(OrderLine line) throws IOException, XMLUtilityException {
    String namespacePrefix = "gme://caCORE.caCORE/3.2/";
    String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetoone.bidirectional";
    Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix);
    Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
    XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller);
    File myFile = new File("OrderLine.xml");
    FileWriter myWriter = new FileWriter(myFile);
    myUtil.toXML(line, myWriter);/*  w w  w . j a v  a2 s . com*/
    myWriter.close();
    return myFile;
}

From source file:test.gov.nih.nci.system.web.client.ProductUpdateClient.java

private static File marshall(Product product) throws IOException, XMLUtilityException {
    String namespacePrefix = "gme://caCORE.caCORE/3.2/";
    String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetoone.bidirectional";
    Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix);
    Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
    XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller);
    File myFile = new File("Product.xml");
    FileWriter myWriter = new FileWriter(myFile);
    myUtil.toXML(product, myWriter);/*  ww  w .  ja v a2  s .  com*/
    myWriter.close();
    return myFile;
}

From source file:Main.java

/**
 * Writes the given string into the given file.
 * //from w w w . j  av  a 2s .co  m
 * @param contents
 *            String representing the file contents.
 * @param filename
 *            Name of the file to be written.
 * @throws IOException
 */
public static void writeFile(String contents, String filename) throws IOException {
    FileWriter fw = new FileWriter(filename);
    fw.write(contents);
    fw.flush();
    fw.close();
}

From source file:Main.java

public static boolean putFileContent(File file, String content) throws IOException {
    FileWriter writer = new FileWriter(file);
    writer.write(content);/*from   w w  w .jav a2s  . c  o  m*/
    writer.flush();
    writer.close();
    return false;
}

From source file:test.gov.nih.nci.system.web.client.HardDriveClient.java

private static File marshall(HardDrive hardDrive) throws IOException, XMLUtilityException {
    String namespacePrefix = "gme://caCORE.caCORE/3.2/";
    String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional";
    Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix);
    Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
    XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller);
    File myFile = new File("HardDrive.xml");
    FileWriter myWriter = new FileWriter(myFile);
    myUtil.toXML(hardDrive, myWriter);//from  ww w .  j  av  a2 s .  c  om
    myWriter.close();
    return myFile;
}

From source file:Main.java

/**
 * This method writes a security token file
 * //from   ww  w.  j  a v a2  s .  c  om
 * @param tokenFilePath
 *            - path of the security token
 * @param token
 *            - security token
 * @return true == succeed, false == failed
 */
private static boolean writeTokenFile(String tokenFilePath, String token) {
    try {
        FileWriter file = new FileWriter(tokenFilePath);
        file.write(token);
        file.close();
    } catch (IOException e) {
        return false;
    }
    return true;
}

From source file:Main.java

public static void writeToFile(String fileName, String toWrite) throws IOException {
    File dir = new File(PHONE_BASE_PATH);
    if (!dir.exists()) {
        dir.mkdirs();/*from   ww  w  .ja va 2  s .  c om*/
    }
    File f = new File(PHONE_BASE_PATH, fileName);
    FileWriter fw = new FileWriter(f, true);
    fw.write(toWrite + '\n');
    fw.flush();
    fw.close();
    f = null;
}