//简单的文件加密
import java.io.*;
import java.lang.String;
import java.awt.*;
import java.awt.event.*;
public class test
{
public static void main(String [] args)
{
char a[]="今晚10点发起攻击".toCharArray();//把字符串存入字符数组中
int n=0;
try
{
File f=new File("secret.txt");//常见文件对象
for(int i=0;i<a.length;i++)
{a[i]=(char)(a[i]^'R');}//加密字符数组
for(int i=0;i<a.length;i++)//输出加密后的内容
{
System.out.print(a[i]);
}
System.out.print("/n");
FileWriter out=new FileWriter(f);
out.write(a,0,a.length);//把字符数组的内容写到secret.txt中
out.close();
FileReader in=new FileReader(f);
char tom[]=new char[10];
System.out.println("密文:");
while((n=in.read(tom,0,10))!=-1)
{
String s=new String(tom,0,n);
System.out.print(s);
}
in.close();
in=new FileReader(f);
while((n=in.read(tom,0,10))!=-1)
{
for(int i=0;i<n;i++)
{
tom[i]=(char)(tom[i]^'R');
}
String s=new String(tom,0,n);
System.out.print(s);
}
}
catch (IOException e)
{
System.err.print(e);
}
}
}
//读取文件时显示读取速度进度条
import javax.swing.*;
import java.io.*;
public class test3
{
public static void main(String[] args)
{
byte b[]=new byte[30];
try
{
FileInputStream input=new FileInputStream("1.txt");
ProgressMonitorInputStream in=
new ProgressMonitorInputStream(null,"读取文件",input);
while(in.read(b)!=-1)
{
String s=new String (b);
System.out.print(s);
Thread.sleep(100);
}
}
catch (Exception e)
{
System.out.print(e);
}
}
}