Package br.com.neto.main

Source Code of br.com.neto.main.EscreverArquivoTxt

package br.com.neto.main;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import br.com.neto.util.Constantes;

public class EscreverArquivoTxt {
 
  @SuppressWarnings("static-access")
  public static void main(String[] args) {
   
    Constantes c = Constantes.getInstance();
    File arquivo = new File(c.FILE_DIRETORIO + c.SLASH + "album.txt");
    File arquivoBkp = new File(c.FILE_DIRETORIO + c.SLASH + "album_bkp.txt");

    // Extrutura try-with-resources do Java 7
    try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(arquivo)));
      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(arquivoBkp)));){
     
      String line = br.readLine();
      do{
        bw.write(line);
        bw.newLine();
      }while((line = br.readLine()) != null);
     
    }catch(IOException ioe){
      System.out.println(ioe.getMessage());
    }

  }

}
TOP

Related Classes of br.com.neto.main.EscreverArquivoTxt

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.