Wednesday, April 1, 2020

Writing a String to a txt file using Java

//Put this at the top of the file:
import java.io.*;
import java.util.*;
BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
//Add this to write a string to a file
//
try {

    out
.write("aString\nthis is a\nttest");  //Replace with the string
                                            
//you are trying to write
}
catch (IOException e)
{
   
System.out.println("IO Exception occurred: "+ e);
}
finally
{
    out
.close();
} source: stackoverflow https://stackoverflow.com/questions/10390254/how-do-you-write-a-string-to-a-text-file

No comments:

Post a Comment

Class IX IT notes: Part A, Unit 1, Session 3.

 IT notes class 9 Part A Unit 1: COMMUNICATION SKILLS session 3: VISUAL AND WRITTEN METHODS OF COMMUNICATION Q1. What is Visual Communicatio...