转换斜杠
import java.io.FileInputStream;
/**
* @author yl
* @version 0.1
* @see 对正斜杠和反斜杠的处理 ,把所有的斜杠进行处理,多个连续的斜杠,取开始的第一个
* --2009.12.21
*
*/
public class Sign {
/**
* @param path
* @return 路径之后加上“\”
*/
public static String AddSignLast_Z(String path){
path=SignSolve(path);
if(path!=null&&path!=""){
if((int) path.charAt(path.length()-1)==92){
}else if((int) path.charAt(path.length()-1)==47){
path=path.substring(0,path.length()-1);//把未尾的“/”去掉
path+="\\";
}else{
path+="\\";
}
}
return path;
}
/** 
* @param path
* @return 路径之后加上“/”
*/
public static String AddSignLast_F(String path){
path=SignSolve(path);
if(path!=null&&path!="")
if((int) path.charAt(path.length()-1)==47){
}else if((int) path.charAt(path.length()-1)==92){
path=path.substring(0,path.length()-1);//把未尾的“\”去掉
path+="/";
}else{
path+="/";
}
return path;
}
/** 
* @param path
* @return 路径中的所有斜杠换成“\”
* @exception java.lang.StringIndexOutOfBoundsException
*/
public static String ReplaceAll_Z(String path){
path=SignSolve(path);
if(path!=null&&path!=""){
placeAll("/", "\\\\");
}
return path;
}
/
** 
* @param path
* @return 路径中的所有斜杠换成“/”
* @exception java.lang.StringIndexOutOfBoundsException 
*/
public static String ReplaceAll_F(String path){
path=SignSolve(path);
if(path!=null&&path!=""){
placeAll("\\\\", "/");
}
return path;
}
/**
* @param path
* @return curPath
* @see 把path中的所有的多个“\”“/”转成开始的第一个
*/
public static String SignSolve(String path){
int mark = 0;
String curPath = "";
for (int i = 0; i < path.length(); i++) {
//ASCII比对“/”=47
if ((int) path.charAt(i) == 47) {
mark++;
if (mark == 1)
curPath += path.charAt(i);
} else if ((int) path.charAt(i) == 92) {
mark++;
if (mark == 1)
curPath += path.charAt(i);
} else {
mark = 0;
}
/
/ System.out.print(mark);
if (mark == 0) {
// System.out.println(path.charAt(i));
curPath += path.charAt(i);
}
}
return curPath;
}
public static void main(String[] args) {
/*Document doc;
String path="";
try {
FileInputStream fileReader = new FileInputStream("l");
SAXBuilder sa = new SAXBuilder();
doc = sa.build(fileReader);
Element configRoot = RootElement();
Element connect = Child("connect");
Element epackagePath = Child("packagePath");
if(epackagePath != null)
{
path = Text();
} else
{
path = " ";
replaceall()}
}catch (Exception e) {
// TODO: handle exception
}
System.out.println("curPath:"+path);
System.out.println(AddSignLast_F(path));
System.out.println(AddSignLast_Z(path));
System.out.println(ReplaceAll_F(path));
System.out.println(ReplaceAll_Z(path));
*/
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。