“黑馬程式設計師”編寫一個可以獲取副檔名的函式,形參接收一個檔名字串,返回一個副檔名字串。
import java.io.*;
/**
* 第六題: 編寫一個可以獲取副檔名的函式,形參接收一個檔名字串,返回一個副檔名字串。
* @author Administrator
*
*/
public class Test6 {
public static void main(String[] args){
File file=new File("D:\\hahaha.txt");
String name=file.getName();
System.out.println("拓展名為:"+getFileExtension(name));
}
public static String getFileExtension(String name){
String tz=name.substring(name.lastIndexOf(".")+1);
return tz;
}
}