자바(Java)

자바 개행문자 추가 파일 쓰기

xemaker 2019. 8. 5. 19:31
public class FileWriterTest{

  public static void main(String[] args){
    System.out.println("Start");
    String txt="테스트";
    String path="D:\\batch\\";
    File f=new File(path);

    String pathFile="";
    String fileName="text";
    String ext=".txt";

    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");

    Date date = new Date();

    String yyyyMMdd=sdf.format(date);

    pathFile=fileName+"_"+yyyyMMdd+ext;

    Calendar cal =new GregorialCalendar();

    cal.add(Calendar.DATE, -1_;

    String yest=sdf.format(cal.getTime(););

    pathFile=path+pathFile;

    try{
      if(!f.isDirectory()){
         f.mkdir();
      }

      PrinterWriter pw = new PrintWriter(new BufferedWriter (new BufferedWriter(new FileWriter(pathFile))));

     pw.println(txt);
     pw.println(txt);
     pw.flush();
     pw.close();

   }catch(Exception e){
      e.printStackTrace();
   }
   System.out.println("End");
  }
}