Answers for "how to write string to file javaa"

1

java write to file

import java.io.FileWriter;   // Import the FileWriter class
import java.io.IOException;  // Import the IOException class to handle errors

public class WriteToFile {
  public static void main(String[] args) {
    try {
      FileWriter fw = new FileWriter("C:/path/to/filename.txt");
      fw.write("this is how u write a string");
	  fw.write(String.valueOf(108)); // cast number to string
      myWriter.close();
    } catch (IOException e) {
        ..
    }
  }
}
Posted by: Guest on June-14-2021
1

java write to file

PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
Posted by: Guest on April-26-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language