package writetofile;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
/**
*
* @author nurhak.kaya
*/
public class WriteToFile {
public static void main(String[] args) {
File file = new File("text.txt");
String data = "This is a sample text data!";
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
/**
*
* @author nurhak.kaya
*/
public class WriteToFile {
public static void main(String[] args) {
File file = new File("text.txt");
String data = "This is a sample text data!";
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Comments
Post a Comment