将字符串中大写转小写,小写转大写

时间:2021-09-08 23:57:49

import java.io.File;
/**
* 文件名大写转小写,小写转大写
* @author zjq
*
*/
public class EditName {

public static void main(String[] args) {
File file = new File("D:\\Files\\DataSourceFile02.zip");
String name = file.getName();

String fileName = name.substring(0, name.lastIndexOf("."));
System.out.println(fileName);

StringBuilder sb = new StringBuilder();

if (fileName!=null) {
for (int i = 0; i < fileName.length(); i++) {
char c = fileName.charAt(i);
if (Character.isUpperCase(c)) {
// System.out.print(c+" ");
// System.out.print(Character.toLowerCase(c)+" ");
sb.append(Character.toLowerCase(c));
} else if(Character.isLowerCase(c)){
sb.append(Character.toUpperCase(c));
}
}
}

System.out.println(sb.toString()+"02");
}
}

相关文章