⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example7_6.java

📁 《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌-源程序
💻 JAVA
字号:
/*
 * Example7_6.java
 *
 * Created on 2006年10月19日, 上午10:33
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package example7_6;
import java.io.*;
/**
 *
 * @author Administrator
 */
public class Example7_6 {
    
    /** Creates a new instance of Example7_6 */
    public Example7_6() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws Exception {
        // TODO code application logic hereint size;
        int size;
InputStream f =
new FileInputStream("FileInputStreamDemo.java");
System.out.println("Total Available Bytes: " +(size = f.available()));
int n = size/40;
System.out.println("First " + n +
" bytes of the file one read() at a time");
char a[]=new char[n];
OutputStream f0 = new FileOutputStream("file1.txt");
for (int i=0; i < n; i++) {
System.out.print(a[i]=(char) f.read());
f0.write(a[i]);
}
f0.close();
System.out.println("\nStill Available: " + f.available());
System.out.println("Reading the next " + n +
" with one read(b[])");
byte b[] = new byte[n];
if (f.read(b) != n) {
System.err.println("couldn't read " + n + " bytes.");
}
OutputStream f1 = new FileOutputStream("file2.txt");
f1.write(b);
f1.close();
System.out.println(new String(b, 0, n));
System.out.println("\nStill Available: " + (size = f.available()));
System.out.println("Skipping half of remaining bytes with skip()");
f.skip(size/2);
System.out.println("Still Available: " + f.available());
System.out.println("Reading " + n/2 + " into the end of array");
if (f.read(b, n/2, n/2) != n/2) {
System.err.println("couldn't read " + n/2 + " bytes.");
}
OutputStream f2 = new FileOutputStream("file3.txt");
f2.write(b,b.length-b.length/2,b.length/2);
f2.close();
System.out.println(new String(b, 0, b.length));
System.out.println("\nStill Available: " + f.available());
f.close();
        
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -