Skip to content

Commit

Permalink
Create FileWrite.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Shalini-2209 authored Oct 20, 2020
1 parent 303be3e commit f59d53e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Java_Programs_for_beginners/FileWrite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileWrite {
public static void main(String[] args) {
String data = "Hello world is printed here.";
try {
OutputStream out = new FileOutputStream("output.txt");
byte[] dataBytes = data.getBytes();

out.write(dataBytes);
System.out.println("Data is written to the file.");
out.close();


} catch (IOException e) {
System.out.println("Error!" + e);
}
}
}

0 comments on commit f59d53e

Please sign in to comment.