자바(Java)
자바 파일 쓰기
xemaker
2019. 8. 5. 19:28
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();
}
BufferedWriter fw=new BufferedWriter(new FileWriter(pathFile));
fw.write(txt);
fw.write(txt);
fw.flush();
fw.close();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("End");
}
}
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();
}
BufferedWriter fw=new BufferedWriter(new FileWriter(pathFile));
fw.write(txt);
fw.write(txt);
fw.flush();
fw.close();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("End");
}
}