file

原创 2018年04月17日 11:53:38
package test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.io.Writer;
import java.util.Scanner;

public class helloworld {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		/*Reader re = new FileReader("d:\\test.txt");
		Writer wr = new FileWriter("d:\\test2.txt");
		
		char[] ch = new char[10];
		int len = 0;
		while((len = re.read(ch))!=-1)
		{
			wr.write(ch, 0, len);
		}
		re.close();
		wr.close();
		
		
		InputStream is = new FileInputStream("d:\\test.txt");
		OutputStream os = new FileOutputStream("D:\\test3.txt");
		byte[] bb = new byte[10];
		
		while((len = is.read(bb))!=-1)
		{
			os.write(bb, 0, len);
		}
		is.close();
		os.close();*/
		
		/*St s = new St(1, 2, 3);
		ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("d:\\St.dat"));
		ObjectInputStream is = new ObjectInputStream(new FileInputStream("d:\\St.dat"));
		
		os.writeObject(s);
		Object obj = is.readObject();
		if(obj instanceof St)
		{
		    St ss = (St)obj;
		    System.out.println(ss);
		}
		
		
		os.close();
		is.close();*/
		
		/*int[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
		
		RandomAccessFile raf = new RandomAccessFile("d:\\test5.txt", "rw");
		
		for(int i = 0;i<data.length;i++)
		{
			raf.writeInt(data[i]);
		}
		System.out.println(raf.getFilePointer());
		raf.seek(0);
		for(int i = 0;i<data.length;i++)
		{
			System.out.println("pointer:"+raf.getFilePointer());
			System.out.println(raf.readInt());
		}
		raf.seek(0);
		raf.skipBytes(25);
		System.out.println(raf.readInt());
		raf.close();*/
		
		
		/*PrintStream ps = new PrintStream("d:\\test.txt");
		ps.print("adasdasdasdasd");
		ps.println(1324651321657614634136D);
		ps.close();*/
		
		/*System.setOut(new PrintStream("d:\\test7.txt"));
		System.out.println(321354351);
		System.out.println("sadyiuashkjd");*/
		
		System.setIn(new FileInputStream("d://test7.txt"));
		Scanner reader = new Scanner(System.in);
		
		String line = reader.nextLine();
		System.out.println(line);
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shadowam/article/details/79972799
收藏助手
不良信息举报
您举报文章:file
举报原因:
原因补充:

(最多只允许输入30个字)