我想用这个程序实现输入unix中的rwxrwxrwx权限自动转换为数字权限777
或者输入数字权限自动转换为rwx这种权限,但是功能不行,高手帮忙看看哪里出问题了?
package test;
import java.util.Scanner;
public class QuanXian {
public static void main(String[] args) {
Scanner sca=new Scanner(System.in);
System.out.println("请输入权限:");
String s = sca.next();
if(s.matches("^[r\\-]{1}[w\\-]{1}[x\\-]{1}[r\\-]{1}[w\\-]{1}[x\\-]{1}[r\\-]{1}[w\\-]{1}[x\\-]{1}$")){
String ss = s.substring(0,3);
String rr = s.substring(3,6);
String tt = s.substring(6,9);
int num = 0;
if("r".equals(ss.substring(0,1))){
num = num + 4;
}
if("w".equals(ss.substring(1,2))){
num = num + 2;
}
if("x".equals(ss.substring(2,3))){
num = num + 1;
int num1 = 0;
if("r".equals(tt.substring(0,1))){
num1 = num1 + 4;
}
if("w".equals(tt.substring(1,2))){
num1 = num1 + 2;
}
if("x".equals(tt.substring(2,3))){
num1 = num1 + 1;
}
int num2 = 0;
if("r".equals(rr.substring(0,1))){
num2 = num2 + 4;
}
if("w".equals(rr.substring(1,2))){
num2 = num2 + 2;
}
if("x".equals(rr.substring(2,3))){
num2 = num2 + 1;
}
System.out.println(num+""+num1+""+num2);
}else if(s.matches("^[0-7]{1}[0-7]{1}[0-7]{1}$")){
String q = "";
if("0".equals(s.substring(0,1))){
q =q+"---";
}else if("1".equals(s.substring(0,1))){
q = q+"--x";
}else if("2".equals(s.substring(0,1))){
q = q+"-w-";
}else if("3".equals(s.substring(0,1))){
q = q+"-wx";
}else if("4".equals(s.substring(0,1))){
q = q+"r--";
}else if("5".equals(s.substring(0,1))){
q = q+"r-x";
}else if("6".equals(s.substring(0,1))){
q = q+"rw-";
}else if("7".equals(s.substring(0,1))){
q = q+"rwx";
}
String q1 = "";
if("0".equals(s.substring(1,2))){
q1 =q1+"---";
}else if("1".equals(s.substring(1,2))){
q1 = q1+"--x";
}else if("2".equals(s.substring(1,2))){
q1 = q1+"-w-";
}else if("3".equals(s.substring(1,2))){
q1 = q1+"-wx";
}else if("4".equals(s.substring(1,2))){
q1 = q1+"r--";
}else if("5".equals(s.substring(1,2))){
q1 = q1+"r-x";
}else if("6".equals(s.substring(1,2))){
q1 = q1+"rw-";
}else if("7".equals(s.substring(1,2))){
q1 = q1+"rwx";
}
String q2 = "";
if("0".equals(s.substring(2,3))){
q2 =q2+"---";
}else if("1".equals(s.substring(2,3))){
q2 = q2+"--x";
}else if("2".equals(s.substring(2,3))){
q2 = q2+"-w-";
}else if("3".equals(s.substring(2,3))){
q2 = q2+"-wx";
}else if("4".equals(s.substring(2,3))){
q2 = q2+"r--";
}else if("5".equals(s.substring(2,3))){
q2 = q2+"r-x";
}else if("6".equals(s.substring(2,3))){
q2 = q2+"rw-";
}else if("7".equals(s.substring(2,3))){
q2 = q2+"rwx";
}
System.out.println(q+q1+q2);
}else{
System.out.println("输入错误!");
return;
}
}
}
}