获取文件路径

String fName =" D:\\C#_Source\\test\\uploadFile\\test.xlsx";

// 方法一:

File tempFile =new File( fName.trim());
 
String fileName = tempFile.getName();
 
System.out.println("fileName = " + fileName);

// 方法二:

String fName = fName.trim();
 
String fileName = fName.substring(fName.lastIndexOf("/")+1);
//或者
String fileName = fName.substring(fName.lastIndexOf("\\")+1);
 
System.out.println("fileName = " + fileName);

// 方法三:

String fName = fName.trim();
 
String temp[] = fName.split("\\\\");
/**
*split里面必须是正则表达式,"\\"的作用是对字符串转义
*/
 
String fileName = temp[temp.length-1];
 
System.out.println("fileName = " + fileName);
 

你可能感兴趣的:(c#)