Home  >  Forum  >  Core Java
Post New Query

how to write a string in a file in java

Asked on June 24, 2015
how to write a string in a file in java

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
System.out.println("Please check the file directory");
} catch (Exception ex) {


Replied on June 24, 2015
To write a String
fileWriter.write("My first String to save");

Write Answer

©2022 concretepage.com | Privacy Policy | Contact Us