package com;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class X {
public static void main(String[] args) {
/*
* 第一个读取该文件的字节大小
*/
/*int a = 0;
FileInputStream i = null;
try
{
i = new FileInputStream("G:\\JAVA\\视频\\04243\\cce.txt");
}catch(
FileNotFoundException e)
{
System.out.println("找不到指定的文件");
System.exit(-1);
}try
{
long n = 0;
while ((a = i.read()) != -1) {
System.out.println((char) a);
;
n++;
}
i.close();
System.out.println("\n\n共读取了" + n + "个字节");
}catch(
IOException e1)
{ System.out.println("读取文件时出现异常"); System.exit(-1); }
*/
/*
*
* 第二个复制原有文件
* */
/* int a2 = -1;
FileInputStream i = null;
FileOutputStream o = null;
try {
i = new FileInputStream("G:\\JAVA\\视频\\04243\\cce.txt");
o = new FileOutputStream("G:\\JAVA\\视频\\04243\\fileNew.txt");
while ((a2 = i.read()) != -1) {
o.write(a2);
}
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
System.exit(-1);
} catch (IOException e) {
System.out.println("文件复制出错");
System.exit(-1);
}
System.out.println("文件成功复制");
}
}*/
/*
* 第三读取文件内容
* */
/*FileReader f = null;
int i = 0;
try {
f =new FileReader("G:\\JAVA\\视频\\04243\\cce.txt");
while ((i = f.read())!= -1) {
System.out.println((char)i);
}
f.close();
} catch (FileNotFoundException e) {
System.out.println("文件未找到");
System.exit(-1);
} catch (IOException e) {
System.out.println("读取文件时出现异常");
System.exit(-1);
}*/
/*
* 第四自动打创建一个unicode000.dat文件 并且输入55555个字符。
*
* */
/* FileWriter we = null;
try {
we = new FileWriter("G:\\JAVA\\视频\\04243\\unicode000.dat");
for (int ir = 1; ir <= 55555; ir++) {
we.write(ir);
}
} catch (IOException e) {
System.out.println("写入文件出错 !");
System.exit(-1);
}*/
/*
* 第五个取50个0-1之间的随机数打印到文件中并显示在控制台上
* */
/*try {
BufferedWriter b = new BufferedWriter(new FileWriter("G:\\JAVA\\视频\\04243\\cce.txt"));
BufferedReader r = new BufferedReader(new FileReader("G:\\JAVA\\视频\\04243\\cce.txt"));
String a = null;
for (int i = 0; i < 50; i++) {
a = ""+ Math.random();//随机数0-1之间的
//b.write(a);这两个是一样的
b.append(a);//等同于上面
b.newLine();//换行
}
b.flush();
while ((a = r.readLine())!= null) {
System.out.println(a);
}
r.close();
b.close();
} catch (IOException e) {
}*/
/*
* 第六个做标记
* */
/*try {
FileInputStream f = new FileInputStream("G:\\JAVA\\视频\\04243\\cce.txt");
BufferedInputStream s = new BufferedInputStream(f);
int c = 0;
System.out.println((char)s.read());
System.out.println((char)s.read());
System.out.println("标记位置");
s.mark(33);
for (int i = 0; i < 10 && (c = s.read())!= -1; i++) {
System.out.println((char)c);
}
System.out.println();
System.out.println("回到mark标记的那个地方");
s.reset();
for (int i = 0; i < 10 && (c = s.read())!= -1; i++) {
System.out.println((char)c);
s.close();
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
} */
}
}