- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class BufferedInputStreamTest {
- public static void main(String[] args) throws IOException {
- File file = new File("c:\\mm.txt");
- FileInputStream fis = new FileInputStream(file);
- BufferedInputStream bis = new BufferedInputStream(fis);
- byte[] contents = new byte[1024];
- int byteRead = 0;
- String strFileContents;
- try {
- while((byteRead = bis.read(contents)) != -1){
- strFileContents = new String(contents,0,byteRead);
- System.out.println(strFileContents);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- bis.close();
- }
- }
- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class ReadFileTest {
- public static void main(String[] args) throws IOException {
- File file = new File("c:\\mm.txt");
- FileInputStream fis = new FileInputStream(file);
- BufferedInputStream bis = new BufferedInputStream(fis);
- while(bis.available() > 0){
- System.out.print((char)bis.read());
- }
- bis.close();
- }
- }
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- public class BufferedInputStreamCopyFile {
- public static void main(String[] args) throws IOException {
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:\\电影\\sn.ts"));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("d:\\电影sn1.ts"));
- int i;
- do{
- i = bis.read();
- if(i != -1){
- bos.write(i);
- }
- }while(i != -1);
- bis.close();
- bos.close();
- }
- }
时间: 2024-10-12 20:53:24