Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Task1{
- public static void main(String[] args){
- // Write to file
- try {
- OutputStream output_stream_object = new FileOutputStream("Task1_test.txt");
- Integer data = 809;
- byte[] data_bytes = data.toString().getBytes();
- output_stream_object.write(data_bytes);
- System.out.println("Successfully wrote to the file!");
- output_stream_object.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- // Read from file
- try {
- InputStream input_stream_object = new FileInputStream("Task1_test.txt");
- byte[] array_data = new byte[input_stream_object.available()];
- input_stream_object.read(array_data);
- String full_data = new String(array_data);
- System.out.println("Successfully read from the file!");
- System.out.println("Data from the file: ");
- System.out.println(full_data);
- input_stream_object.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment