如何替换filepath,在该文件路径中删除一些路径并替换\ to /

时间:2016-02-08 05:52:23

标签: java

fi.write(file);
out.println("filepath"+file.getAbsolutePath());
System.out.println("above is actual paht and bellow are replace path");
String proPic = file.getAbsolutePath();
HPIUGS.setImageName(proPic);
System.out.println(HPIUGS.getImageName());
out.println("Uploaded Filename: " + fileName + "<br>");
out.println(filePath);

输出:

C:\Users\Peado Inffitech 5\Desktop\eclipse\jsp\UsersPanel\upload\uploadsPenguins.jpg

我改变输出为:

/jsp/UsersPanel/upload/uploadsPenguins.jpg

1 个答案:

答案 0 :(得分:0)

String gotString  = "C:\\Users\\Peado Inffitech 5\\Desktop\\eclipse\\jsp\\UsersPanel\\upload\\uploadsPenguins.jpg";


String newString = gotString.replace("C:\\Users\\Peado Inffitech 5\\Desktop\\eclipse", "").replace("\\", "/");

System.out.print(newString);

如果我没有错过你的观点,这对你有用。