以前觉得java基础学完就可以申请进就业班学习,
现在学完大部分了越来越觉得还差的太远.
就业班进度飞快,一系列基础和预习准备充分才行!
不过不论怎样,至少方向没错.
up!
- /**
- *
- */
- package day19_IOStream;
- /**
- * @author always
- * @字节流学习
- */
- import java.io.*;
- public class FileStream {
- public static void main(String[] args) throws IOException {
- // writeFile();
- // readFile_1();
- // readFile_2();
- readFile_3();
- }
-
- public static void readFile_3() throws IOException{
- FileInputStream fis = new FileInputStream("D:\\java\\java027\\Demo.txt");
- byte[] buf = new byte[fis.available()];
- fis.read(buf);
- System.out.print(new String(buf));
-
- fis.close();
- }
-
- /*字节流读取2*/
- public static void readFile_2() throws IOException {
- FileInputStream fis = new FileInputStream("D:\\java\\java027\\Demo.txt");
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = fis.read(buf)) != -1) {
- System.out.print(new String(buf, 0, len));
- }
-
- fis.close();
- }
-
- /*字节流读取1*/
- public static void readFile_1() throws IOException {
- FileInputStream fis = new FileInputStream("D:\\java\\java027\\Demo.txt");
- int ch = 0;
- while((ch = fis.read()) != -1) {
- System.out.print((char)ch);
- }
-
- fis.close();
- }
- /*字节流输出*/
- public static void writeFile() throws IOException {
-
- FileOutputStream fos = new FileOutputStream("d:\\java\\java027\\Demo.txt");
-
- fos.write("abcdefg\r\nhijklmn".getBytes());
-
- fos.close();
- }
- }
复制代码 |