public static void main(String[] args) {
String filePath = "D:/test.txt";
readTxt(filePath);
}
/**
* 读取文件
* @param filePath
*/
public static void readTxt(String filePath) {
try {
File file = new File(filePath);
if (file.isFile() && file.exists()) {
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader br = new BufferedReader(isr);
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
convert(lineTxt);
}
br.close();
} else {
System.out.println("文件不存在!");
}
} catch (Exception e) {
System.out.println("文件读取错误!");
}
}
/**
* 对传过来的字符串进行反序显示并大小写转换
* @param lineTxt
*/
public static void convert(String lineTxt) {
// 字符串转成char数组
char[] ch = lineTxt.toCharArray();
StringBuffer buffer = new StringBuffer();
for (int i = lineTxt.length() - 1; i >= 0; i--) {
if (ch[i] >= 'A' && ch[i] <= 'Z') {
buffer.append(String.valueOf(ch[i]).toLowerCase());
} else if (ch[i] >= 'a' && ch[i] <= 'z') {
buffer.append(String.valueOf(ch[i]).toUpperCase());
}
}
System.out.println(buffer);
}