"Android Test" "essay" Create a Chinese folder on the phone with the command line

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.