Home  >  Forum  >  Core Java
Post New Query

how to write a string in a file in java


joined on
September 16,2014
Asked on June 24,2015
how to write a string in a file in java
joined on
March 15,2013
Replied on June 24,2015

Using java io package you can create string to a file. To do this you need to import the import java.io.FileWriter; package in your code. See the example

import java.io.FileWriter;

public class WriteAFile {
public static void main(String[] args) {
try {
FileWriter writer  = new FileWriter("D:/Eclipse_Workspace/SerializationFile/WriteAFile.txt");  // path to save the file
writer.write("First file to write");  // string that you want to write in your file
writer.close();
System.out.println("Please check the file directory");
} catch (Exception ex) {
ex.printStackTrace();
}
}

}

joined on
March 05,2015
Replied on June 24,2015

To write a String
fileWriter.write("My first String to save");

Write Answer



Sitewide-Feb4of4234x60





Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us