I do not know why I wrote a phone in the command line to create a file code, and later because of the need, the new folder needs to be expressed in Chinese, because the intuitive, and then found strange garbled.
Tried a variety of coding format, finally succeeded, is the various coding format out of the wrong, the first is correct.
Okay, no more talking, on the source.
1 Public voidShellonecommand (String cmd)2 { 3((mainactivity) maincontext). Threadupdatelogtoui ("Runshell:" +cmd, commonvar.log_show);4 5 Try6 {7Process process = Runtime.getruntime (). EXEC ("su");8DataOutputStream OS =NewDataOutputStream (Process.getoutputstream ());9cmd =NewString (Cmd.getbytes (), "Iso-8859-1");TenOs.writebytes (cmd + "\ n")); OneOs.writebytes ("exit\n"); A Os.flush (); - os.close (); - process.waitfor (); the}Catch(Exception e) - { - e.getstacktrace (); - } +}
The above code is used in this way:
Shellonecommand ("mkdir-p/storage/emulated/0/Chinese folder ");
In fact, the most critical part of the above code is the 9th line:
New String (Cmd.getbytes (), "iso-8859-1");
First, the CMD is converted to byte and then converted to the ISO-8859-1 encoding format.
In fact, the difficulty is that if the encoding format is determined? Because I think there will only be utf-8 and gb2312 in the Android phone encoding format, but actually out of such a wonderful coding format.
What happens after that? That can only be one try, so make a list of commonly used encoding formats:
/** 7-bit ASCII character, also known as the basic Latin block of the iso646-us, Unicode character set*/ "Us-ascii"; /** ISO Latin alphabet, also known as Iso-latin-1*/ "iso-8859-1"; /** 8-bit UCS conversion format*/ "UTF-8"; /** 16-bit UCS conversion format, Big Endian (lowest address holds high byte) byte order*/ "Utf-16be"; /** 16-bit UCS conversion format, Little-endian (highest address holds low byte) byte order*/ "Utf-16le"; /** 16-bit UCS conversion format, byte order identified by an optional byte order mark*/ "UTF-16"; /** Chinese Super large character set*/ "GBK"
"Android Test" "essay" Create a Chinese folder on the phone with the command line