Lập trình Java cơ bản : Luồng và xử lý file part 3

Các luồng file • Được sử dụng để xuất nhập với file. • Luồng nhập từ file: FileInputStream • FileInputStream(String name) • FileInputStream(File f) • Luồng xuất ra file: FileOutputStream • FileOutputStream(String name) • FileOutputStream(File f) • FileOutputStream(String name, boolean append) | Các luồng file Được sử dụng để xuất nhập với file. Luồng nhập từ file Fileinputstream FileinputStream String name FileinputStream File f Luồng xuất ra file FileOutputStream FileOutputStream String name FileOutputStream File f FileOutputStream String name boolean append Phương thức nhập xuất của các luồng file giống như của các luồng nhập xuất cơ bản 11 Ví dụ Đọc và hiển thị file v1 import . public class ReadFile public static void main String args try FileInputStream f new FileInputStream int ch while ch -1 char ch catch FileNotFoundException d File not found catch IOException d Can not read file Ví dụ Ghi dữ liệu ra file import . public class WriteFile public static void main String args byte buffer new byte 80 try Enter a string to write to file int num buffer FileOutputStream f new FileOutputStream buffer 0 num catch IOException e Error IO file .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.