1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng lập trình hướng đối tượng vào ra file với java TS nguyễn mạnh hùng

19 231 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 19
Dung lượng 276,94 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

InputStream Vào từ file: try { •InputStream input = new FileInputStream"input.txt"; while input .read != -1 { //do something with data..... OutputStream Ra file: try { •OutputStream out

Trang 1

Lập hướng đối tượng

Vào ra file với Java

Giảng viên: TS Nguyễn Mạnh Hùng

Học viện Công nghệ Bưu chính Viễn thông (PTIT)

Trang 2

Nội dung

Trang 3

InputStream/OutputStream

Trang 4

InputStream

Vào từ file:

try {

•InputStream input = new FileInputStream("input.txt");

while (( input read()) != -1) {

//do something with data

}

input close();

} catch (IOException e){

System.out.println(e);

}

Trang 5

OutputStream

Ra file:

try {

•OutputStream output = new

FileOutputStream("output.txt");

output write(1111111);

output close();

} catch (IOException e){

System.out.println(e);

}

Trang 6

BufferedInputStream/ BufferedOutputStream

Trang 7

BufferedInputStream

Vào từ file:

try {

BufferedInputStream input = new

BufferedInputStream( new FileInputStream("input.txt"));

byte [] in = new byte [1024];

while (( input read(in)) != -1) {

//do something with data

}

input close();

} catch (IOException e){

System.out.println(e);

}

Trang 8

BufferedOutputStream

Ra file:

try {

BufferedOutputStream output = new

BufferedOutputStream( new FileOutputStream("output.txt"));

output write(int input);

output write(byte[] buff, int start, int length);

output close();

} catch (IOException e){

System.out.println(e);

}

Trang 9

DataInputStream/ DataOutputStream

Trang 10

DataInputStream

Vào từ file:

try {

DataInputStream input = new

DataInputStream( new FileInputStream("input.txt"));

String in = input readUTF();

//do something with data

input close();

} catch (IOException e){

System.out.println(e);

}

Trang 11

DataOutputStream

Ra file:

try {

DataOutputStream output = new

DataOutputStream( new FileOutputStream("output.txt"));

output writeUTF("some thing to write");

output close();

} catch (IOException e){

System.out.println(e);

}

Trang 12

BufferedReader/ BufferedWriter

Trang 13

BufferedReader

Vào từ file:

BufferedReader input = new

BufferedReader( new FileInputStream("input.txt"));

Trang 14

BufferedWriter

Ra file:

BufferedWriter output = new

BufferedWriter( new FileOutputStream("output.txt"));

Trang 15

InputStreamReader/ OutputStreamWriter

Trang 16

InputStreamReader

Vào từ file:

InputStreamReader input = new

InputStreamReader( new FileInputStream("input.txt"));

Trang 17

OutputStreamWriter

Ra file:

OutputStreamWriter output = new

OutputStreamWriter( new FileOutputStream("output.txt"));

Trang 18

Bài tập

 Viết chương trình nhập một ô số sudoku từ

bàn phím rồi ghi ra file

 Viết chương trình đọc nội dung một ô số

sudoku từ file rồi hiển thị lên màn hình

Trang 19

Questions?

Ngày đăng: 03/12/2015, 18:33

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm