자바에서 파일입출력 어떻게해요???

조회수 3200회

발생하는 문제 및 실행환경

텍스트파일을 생성하고 싶어요 어떻게해요??

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기
    PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
    writer.println("The first line");
    writer.println("The second line");
    writer.close();
    

    텍스트파일 만드는법.

    byte data[] = ...
    FileOutputStream out = new FileOutputStream("the-file-name");
    out.write(data);
    out.close();
    

    바이너리 파일 만드는법 Java 7+에서 Files로 텍스트파일 만드는법

    List<String> lines = Arrays.asList("The first line", "The second line");
    Path file = Paths.get("the-file-name.txt");
    Files.write(file, lines, Charset.forName("UTF-8"));
    //Files.write(file, lines, Charset.forName("UTF-8"), StandardOpenOption.APPEND);
    

    바이너리 파일 만드는법

    byte data[] = ...
    Path file = Paths.get("the-file-name");
    Files.write(file, data);
    //Files.write(file, data, StandardOpenOption.APPEND);
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)