1:获取路径:
1:Scanner sca = new Scanner(new FileInputStream(new File(path)),"GBK");
2:File f = new File(this.getClass().getResource("/").getPath());
3:File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath() ;
4:URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
5:System.out.println(System.getProperty("user.dir"));
6:System.out.println( System.getProperty("java.class.path"));
2:去空格
1. String.trim() trim()是去掉首尾空格
2:str.replace(" ", ""); 去掉所有空格,包括首尾、中间
3:.或者replaceAll(" +",""); 去掉所有空格
4:str = .replaceAll("\\s*", ""); 可以替换大部分空白字符, 不限于空格 \s 可以匹配空格、制表符、换页符等空白字符的其中任意一个 :
4:泛型的使用不支持多态
5:extends在类上使用只有上限 public class MyException<T> /* extends Exception*/
在方法上使用可以上限或者下线
public static void fn2_1(List<? extends Number> list){
//Number 或 Number的子类
}
public static void fn2_2(List<? super Number> list){
//Number 或 Number的父类
}
6:泛型方法的使用
public static <T> void test(T t){
}
Demo.<String>test(new String());
7:有对象才能有泛型的概念
泛型只能用包装类或者对象
不能new数组对象 Person<int[]> p3 = null;
静态环境不能用 public static void fn2(){ T a = null; //静态环境不能用 泛型 }
不能用instanceof if(obj instanceof T){ }
异常类不支持泛型 public class MyException<T> /* extends Exception*/
8:时间格式化类
public class ShoppingDateUtil {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
public static Date parseDate(String txt) throws ParseException {
return simpleDateFormat.parse(txt);
}
}
9:通过集合和读取文件,读取文件里面的数据