本文共 4591 字,大约阅读时间需要 15 分钟。
import java.io.*;public class book { public static void main(String[] args) throws Exception { File dst = new File("Exercise17_01.txt"); FileWriter fw = new FileWriter(dst,true); try( PrintWriter output = new PrintWriter(fw);){ for(int i=0;i<100;i++) { output.print((int) (Math.random() * 100)+" "); } output.print('\n'); } }}
import java.io.*;public class book { public static void main(String[] args) throws Exception { try(FileOutputStream musashi = new FileOutputStream("Exercise17_02.dat",true);) { for(int i=0;i<100;i++) musashi.write((int)(Math.random()*100)); } }}
import java.io.*;public class book { public static void main(String[] args) throws Exception { try( FileInputStream yamato = new FileInputStream("Exercise17_02.dat"); ){ int v=0; while(yamato.read()!=-1) v++; System.out.print(v); } }}
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { File yukikaze = new File(args[0]); Scanner input = new Scanner(yukikaze); String nagato=""; while(input.hasNext()) nagato+=input.nextLine(); input.close(); try(DataOutputStream shimakaze = new DataOutputStream(new FileOutputStream(args[1]));){ shimakaze.writeChars(nagato); } }}
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { int[] PoW = { 1,2,3,4,5}; Date KGV = new Date(); double DoY = 5.5; try( ObjectOutputStream Bismark = new ObjectOutputStream(new FileOutputStream("Exercise17_05.dat")); ){ Bismark.writeObject(PoW); Bismark.writeObject(KGV); Bismark.writeDouble(DoY); } try( ObjectInputStream Tilpitz = new ObjectInputStream(new FileInputStream("Exercise17_05.dat")); ){ int[] ss= (int[])(Tilpitz.readObject()); Date jj=(Date)(Tilpitz.readObject()); double bb= Tilpitz.readDouble(); for(int i=0;i
public class book { public static void main(String[] args) throws Exception { RandomAccessFile eagle = new RandomAccessFile("Exercise17_08.dat","rw"); eagle.writeInt(1); eagle.close(); RandomAccessFile victory = new RandomAccessFile("Exercise17_08.dat","rw"); int swordfish = victory.readInt(); swordfish++; victory.setLength(0); victory.writeInt(swordfish); }}
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { System.out.print("Enter the src: "); Scanner input = new Scanner(System.in); String jj = input.next(); System.out.print("Enter the num: "); int num = input.nextInt(); RandomAccessFile src = new RandomAccessFile(jj,"r"); src.seek(0); long llen = src.length()/num; for(int i=1;i<=num;i++){ RandomAccessFile tmp = new RandomAccessFile(jj+"."+i,"rw"); for(long j=0;j
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { System.out.print("Enter the src and dst: "); Scanner input = new Scanner(System.in); String jj = input.next(); String mm = input.next(); RandomAccessFile src = new RandomAccessFile(jj,"r"); RandomAccessFile dst = new RandomAccessFile(mm,"rw"); src.seek(0); for(int i=0;i
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { System.out.print("Enter the src and dst: "); Scanner input = new Scanner(System.in); String jj = input.next(); String mm = input.next(); RandomAccessFile src = new RandomAccessFile(jj,"r"); RandomAccessFile dst = new RandomAccessFile(mm,"rw"); src.seek(0); for(int i=0;i
转载地址:http://auwai.baihongyu.com/