public static void main(String[] args) throws IOException {
//File dir = new File("D:\\files\\file","/file11");
// dir.mkdirs();
File file = new File("../common");
String canoPath = file.getCanonicalPath(); //此种的..做解析
String absPath = file.getAbsolutePath(); // 此种的.. 不做解析
System.out.println(canoPath +" "+absPath);
}
上面是第一点
下面就是读取
try {
FileInputStream fi =new FileInputStream(new File("d:\\a.txt"));
BufferedInputStream bf =new BufferedInputStream(fi);
StringBuffer sb =new StringBuffer();
if(bf.available()>0){
int i = 0;
while(i!=-1){ // 此处不能用fi.read!=-1 这样的话在加上下面的则相当于读了两次
i = bf.read();
sb.append((char)i);
}
}
bf.close();
System.out.println(sb.toString());
BufferedReader br = new BufferedReader(new FileReader("d:\\a.txt"));
String line = "";
while((line=br.readLine())!=null){
System.out.println(line);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}