JAVA怎么转化8进制字符串

例如我得到的字符串为:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx

如果问题得到解决,请点我回答左上角的采纳和向上的箭头

class Untitled {
    public static String toOct(String s)
    {
        String result = "";
        for(char c : s.toCharArray())
        {
            result += "\\" + (c / 64) % 8 +  "" + (c / 8) % 8 + "" + c % 8;
        }
        return result;
    }

    public static String getOct(String s)
    {
        String result = "";     
        for (String i : s.split("\\\\"))
        {
            int sum = 0;
            int base = 64;
            for (char c : i.toCharArray())
            {
                sum += base * ((int)c - '0');
                base /= 8;
            }
            result += Character.toString((char)sum);
        }
        return result;
    }

    public static void main(String[] args) {
        String s = "abcd";
        String o = toOct(s);
        System.out.println(o);
        s = getOct(o);      
        System.out.println(s);
    }
}

运行结果
\141\142\143\144
abcd