写给你了
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
/**
* 文本文件所在的目录
*/
private String textPath="c:\\";
/**
* 读取文本内容
* @param textname 文本名称
* @return
*/
public String readText(String textname){
File file=new File(textPath+File.separator+textname);
try {
BufferedReader br = new BufferedReader(new java.io.FileReader(file));
StringBuffer sb = new StringBuffer();
String line = br.readLine();
while (line != null) {
sb.append(line);
line = br.readLine();
}
br.close();
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* 将内容写到文本中
* @param textname 文本名称
* @param date 写入的内容
* @return
*/
public boolean writeText(String textname,String data){
boolean flag=false;
File filePath=new File(textPath);
if(!filePath.exists()){
filePath.mkdirs();
}
try {
FileWriter fw =new FileWriter(textPath+File.separator+textname);
fw.write(data);
flag=true;
if(fw!=null)
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
return flag;
}
public static void main(String[] args) {
Test test=new Test();
String textname="1.txt";
test.writeText(textname, "你好\r\n你也好");
System.out.println(test.readText(textname));
}
}
package text;
import java.io.FileOutputStream;
import java.util.Arrays;
public class Paixu {
public static int[] a=;
public static StringBuilder stringBuilder=new StringBuilder();
public int[] b=new int[5];//存放排序后的数组
public String arrayA(){
Arrays.sort(a);//由小到大排序
for (int i = a.length-1; i>=0; i--) {
b[4-i]=a[i];
}
for (int i = 0; i < b.length; i++) {
stringBuilder.append(b[i]);//将数组转换成StringBuilder
}
return stringBuilder.toString();
}
static void files(String b) throws Exception{
FileOutputStream file=new FileOutputStream("c:\\out.txt"); //写出到文件
String s=stringBuilder.toString();
byte[] arr=s.getBytes();
for(int i=0;i
}
file.close();
}
public static void main(String[] args) throws Exception{
String string=new Paixu().arrayA();
files(string);
}
}