Tuesday, August 21, 2012

Creating the file using FileOutputStream



package com.jsl.io;

import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.FileOutputStream;

public class FileCreation {
  public static void main(String[] args) {
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    
    try {
      fos = new FileOutputStream("One.txt", true);
      System.out.println("Enter the text");
      bos = new BufferedOutputStream(fos, 512);
      DataInputStream dis = new DataInputStream(System.in);
      char ch;
      while ((ch = (char) dis.read()) != '@') {
        int a = 1 / 0;
        bos.write(ch);
      }
   } catch (Exception e) {
      e.printStackTrace();
   } finally {
          try {
             bos.close();
             fos.close();
          } catch (Exception e) {
             System.out.println("While closing the file :" + e);
          }
   }
   System.out.println("End of main method");
 }
}



No comments:

Post a Comment

Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers

pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"...