Atitit. Software Development Concept Description --io System Area -- Special file name save best practices file name encoding . .. filenameencode
Not a page title saved to each file when there are invalid characters of the problem ...
Usually two processing methods::: replace into a space or use escape ( recommended ) ...
Invalid file name for Windows characters ... /\:* <>\ "| Slash, backslash, colon , asterisk , question mark , about the
Angle brackets , double quotes , tree bars ... and ..."." A point and a "..." The two points are used to denote " current directory " and " parent directory "respectively. Therefore, they also cannot be used as filenames
Linux is basically only a backslash ...
Author:: Old Wow's paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
Public static string Filenameencode (String filenameori) {
/\:* <>\ "|
if (filenameori.equals ("." ))
return "%2e";
if (filenameori.equals (".." ) ))
return "%2e%2e";
map<string, string> MP = (map<string, string>) New closurenoexcpt () {
@Override
Public Object Execute (final object arg0) {
Final map<string, string> MP = New hashmap<string, string> () {
{
This . Put ("*", "%2a");
}
};
Final string[] as = Strutil. Splitbynone ("/\\:?<>\" | " );
for (final String s:as) {
Try {
Mp.put (S, Urlencoder. encode (S, "Utf-8"));
} catch (final unsupportedencodingexception e) {
// TODO auto-generated Catch block
E.printstacktrace ();
}
}
return MP;
}
}.execute (null);
string[] as = Strutil. Splitbynone (Filenameori);
String fname2 = "" ;
for (String s:as) {
fname2 + = Mp.get (s) = = NULL ? S:mp.get (s);
}
return fname2;
}
Atitit. Software Development Concept Description--io System Area--Special file name save best practices file name encoding ... Filenameencode