import java.io.*;
import java.util.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.String;
import java.awt.*;
//
//
// Red
//public class Red
{
public static void main(String []args) throws IOException
{
// int aac;
//输出原文件
System.out.println("Program Beginning ... ...");
FileInputStream inStream = new FileInputStream("E://txt.txt"); //文件放在本程序的
int inread = inStream.available(); //同一文件目录下
byte inword[] = new byte[inread];
int bytesRead = inStream.read(inword,0,inread);
System.out.println(new String(inword,0));
char ttc[] = new char[inread+2];
String readouts[] = new String[10];
System.out.println("...............................");
int cline = 0 ;
int bline = 0 ;
int eline = 0 ;
//一次取一行将原文件内容归纳成按行存储的输入流
ttc[inread] = 13;
ttc[inread+1] = 10;
for(int i = 0 ; i < inread ; i++)
{
ttc[i] = (char) inword[i];
System.out.print(ttc[i]);
if(ttc[i] == 10 || i == (inread-1))
{
eline = i;
if(i == (inread-1))
readouts[cline] = new String(ttc,bline,(eline-bline+3));
else
readouts[cline] = new String(ttc,bline,(eline-bline+1));
bline = i+1;
cline++;
}
}
System.out.println();
System.out.println("...............................");
inStream.close();
//将每行的内容在屏幕上显示一遍
int num =0;
for(int l = 0 ; l < cline ; l++)
{
System.out.print("&&&&&&&&&&&&&&&"+num++ +readouts[l]);
}
System.out.println(); //输入一空行。
//compare 按字典顺序对比,并按照顺序排序
String abba = new String();
for(int bn = 0 ; bn < cline-1 ; bn++)
{
for(int m = 0 ; m < cline-1-bn ; m++)
{
int duibi = readouts[m].compareTo(readouts[m+1]);
if(duibi > 0 )
{
abba = readouts[m];
readouts[m] = readouts[m+1];
readouts[m+1] = abba;
}
}
}
System.out.println("This documents 'flow' has been sort now...");
// cout the sort string 输出排好顺序的每行内容
for(int l = 0 ; l < cline ; l++)
{
System.out.print(readouts[l]);
}
///write string in txt 输出一行...号
System.out.println(".................");
// cout if documents exist判断文件是否存在,不存在则创建一新文件
File testtxt = new File("");
if(testtxt.exists() == false)
{
System.out.println("d.txt is not exist");
System.out.println("Creat new documents now....waiting.....");
testtxt = new File("E://d.txt");
}
else System.out.println("Have found the document /" d.txt/" ");
if(testtxt.exists() == true)
System.out.println("Creat /"d.txt/" successly...Congratulation!!!");
//利用新创立的文件,创建一个输出流,以方便写入文件
FileOutputStream outStream = new FileOutputStream("E://d.txt");
String houl = new String();
//将排好顺序的内容合并到一个字符串中
for(int i = 0 ; i < cline ; i++)
{
houl = houl+readouts[i];
}
//打印该字符串
houl = houl+'/n';
System.out.println(houl);
System.out.println("begin store these data...");
//将此字符串的内容写入输出流所代表的文件
for (int i = 0 ; i < inread ; i++)
{
outStream.write(houl.charAt(i));
}
//关闭输出流
outStream.close();
//创建一新的输入流,并在屏幕显示输入的内容。
System.out.println("This documents stored ok..!~~");
System.out.println("Program Beginning ... ...");
FileInputStream inStreamnew = new FileInputStream("E://d.txt");
int inreadnew = inStreamnew.available();
byte inwordnew[] = new byte[inreadnew];
int bytesReadnew = inStreamnew.read(inwordnew,0,inreadnew);
System.out.println("This is a test for this program...");
System.out.println(new String(inwordnew,0));
//关闭输入流
inStreamnew.close();
}
}