Git Product home page Git Product logo

week9's Introduction

Đề bài :

Java cung cấp sự hỗ trợ mạnh mẽ cho các thao tác I/O liên quan tới các File (đọc, ghi,…). Ví dụ với đọc 1 file text, Java cung cấp nhiều cách khác nhau. Có thể sử dụng FileReader như dưới đây.

BufferedReader in = new BufferedReader(new FileReader("c:\filename.txt")); String str; while ((str = in.readLine()) != null) { System.out.println(str); }

Hoặc có thể sử dụng File.ReadAllLines() như dưới đây. Phương thức này sẽ trả về 1 List các String tương ứng với các dòng của file text.

List lines = Files.readAllLines(Paths.get("C:\filename.txt"));

Yêu cầu: Dựa trên hướng dẫn phía trên, hãy xây dựng lớp tiện ích Utils, sử dụng code mẫu tại: https://github.com/oasis-homework/BaiTapHangTuan/tree/main/week9

a. Viết phương thức static để đọc một tệp .txt từ ổ cứng:

public static String readContentFromFile(String path)

Trong đó biến path là đường dẫn đến tệp cần đọc, lưu ý cả trường hợp đường dẫn tương đối và tuyệt đôi, quản lý file trên hệ điều hành Linux cũng như Windows

b. Viết phương thức static để xuất nội dung một xâu vào 1 tệp trong ổ cứng:

public static void writeContentToFile(String path)

trong đó biến path là đường dẫn đến tệp cần ghi nội dung. Nếu tệp đã có nội dung thì ta xóa nội dung đó trước khi ghi nội dung mới.

c. Tương tự ý câu b nhưng thay vì xóa nội dung cũ đi, ta bổ sung nội dung mới vào cuối tệp hiện tại

d. Viết phương thức static để tìm kiếm một tệp trong một thư mục:

public static File findFileByName(String folderPath, String fileName),

trong đó folderPath là tên thư mục, fileName là tên tệp cần tìm kiếm. Source code mẫu :

https://github.com/oasis-homework/BaiTapHangTuan/tree/main/week9 Điều kiện :

None Mức độ : Khó Tổng số bài làm đúng: 0 Tổng lượt nộp bài: 0

week9's People

Contributors

duynguyen1705 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.