티스토리 뷰

자바(Java)

자바 파일 읽기 및 이동

xemaker 2019. 8. 5. 19:36
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{
      File file =new File(pathFile);
      FileReader fileReader=new FileReader(file);
      BufferedReader bufReader = new BufferedReader(fileReader);
      String line="";
      while( (line = bufReader.readLine())!=null){
        System.out.println(line);
     }
     bufReader.close();

      if(!fm.isDirectory()){
         fm.mkdir();
      }

     Path p=Paths.get(pathFile);
      Path pathMove=Paths.get(movePath);
      Files.move(p, pathMove.resolve(p.getFileName()));

   }catch(Exception e){
      e.printStackTrace();
   }
   System.out.println("End");
  }
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함