日期:2014-05-18 浏览次数:20889 次
var encoding = Encoding.GetEncoding("GB2312"); var path = "C:\\一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一.txt";//153 while (encoding.GetByteCount(path) > 128) { var name = Path.GetFileNameWithoutExtension(path); path = Path.GetDirectoryName(path) + "\\" + name.Substring(0, name.Length - 1) + Path.GetExtension(path); } var bytes = encoding.GetBytes(path);
------解决方案--------------------
稍微修改下
var encoding = Encoding.GetEncoding("GB2312"); var path = "C:\\a\\一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一.txt";//153 var np = path; while (encoding.GetByteCount(np) > 128) { var name = Path.GetFileNameWithoutExtension(np); np = Path.GetDirectoryName(np).TrimEnd('\\') + "\\" + name.Substring(0, name.Length - 1) + Path.GetExtension(np); } File.Move(path, np); var bytes = encoding.GetBytes(np);
------解决方案--------------------
这个问题不难吧。先转化成字节,在截取,再转化成字符串。没什么难度吧!