java学习笔记——学习和代码(二)

春晓    --->   晓春
 春眠不觉晓    晓觉不眠春
 处处闻啼鸟    鸟啼闻处处
 夜来风雨声    声雨风来夜
花落知多少    少多知落花
example1
import java.io.*;
import java.util.*;
public class PoetryReader {
public static void main(String[] args) throws Exception {
FileInputStream fin = new FileInputStream("./xiao.txt");
InputStreamReader isr = new InputStreamReader(fin);
BufferedReader br = new BufferedReader(isr);
PrintWriter pw =
new PrintWriter(new FileOutputStream("./ming.txt"));
List list = new ArrayList();
String str = br.readLine();
while(str != null){
StringBuffer sb = new StringBuffer(str);
StringBuffer sb1 = sb.reverse();//字符取反
list.add(sb1);
System.out.println(sb1);
pw.println(sb1);//执行把读取的字符按行写入新文本
str = br.readLine();
}
pw.close();//一定要记得关闭流
br.close();
System.out.println("-------美丽的分割线----------");
for (int i = list.size(); i > 0; i--) {
//注意调用StringBuffer的toString()
//String a= list.get(i-1).toString();
System.out.println(list.get(i-1));
}
}
}
example2.
import java.io.*;
import java.util.*;
public class PoetryReader2Test {
public static void main(String[] args) throws Exception {
FileInputStream fin = new FileInputStream("./xiao.txt");
InputStreamReader isr = new InputStreamReader(fin);
BufferedReader br = new BufferedReader(isr);
PrintWriter pw =
new PrintWriter(new FileOutputStream("./ming1.txt"));
List list = new ArrayList();
String str = br.readLine();
while (str != null) {
System.out.println(str);
pw.println(str);
char[] arr = str.toCharArray();
int j = arr.length;
char[] arr2 = new char[j];
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[j - 1];
j--;
}
list.add(arr2);
str = br.readLine();
}
pw.close();
br.close();
System.out.println("-------美丽的分割线-----------");
for (int i = list.size(); i > 0; i--) {
char[] arr1 = (char[]) list.get(i - 1);
System.out.println(new String(arr1));
}
}
}


--来自网页客户端
4.jpg 1.jpg
已邀请:

蓝天的外面 - 与善于人,与爱于己

赞同来自: idehub1

和大家早上问个好

--来自网页客户端

要回复问题请先登录注册

Template error, template file not found