1.pythonä¸ä¸ºä»ä¹ä»strå°bytesç转åä¼åºç°ç±»ä¼¼' \x** 'çå½¢å¼
2.pythonä¸ r'',象源瑞士名表源码 b'', u'', f'' çå«ä¹
3.Bytes.toBytes("str")ä¸"str".getBytes()
4.javaä¸çwriteBytes()
pythonä¸ä¸ºä»ä¹ä»strå°bytesç转åä¼åºç°ç±»ä¼¼' \x** 'çå½¢å¼
åèç ï¼è±è¯ï¼Bytecodeï¼é常æçæ¯å·²ç»ç»è¿ç¼è¯ï¼ä½ä¸ç¹å®æºå¨ç æ å ³ï¼éè¦ç´è¯å¨è½¬è¯åæè½æ为æºå¨ç çä¸é´ä»£ç ãåèç é常ä¸åæºç ä¸æ ·å¯ä»¥è®©äººé 读ï¼èæ¯ç¼ç åçæ°å¼å¸¸éãå¼ç¨ãæ令çææçåºåã
åèç 主è¦ä¸ºäºå®ç°ç¹å®è½¯ä»¶è¿è¡å软件ç¯å¢ãä¸ç¡¬ä»¶ç¯å¢æ å ³ãåèç çå®ç°æ¹å¼æ¯éè¿ç¼è¯å¨åèææºå¨ãç¼è¯å¨å°æºç ç¼è¯æåèç ï¼ç¹å®å¹³å°ä¸çèææºå¨å°åèç 转è¯ä¸ºå¯ä»¥ç´æ¥æ§è¡çæ令ã
é¤äºä½ æç»å¥½å¥ç"\x"ä¹å¤,åºè¯¥é½ä¸é¾ç解:ä¸ä¸ªåèç 对åºäºä¸ä¸ªæ±å.
"\x"æ¯PEPä¹å°±æ¯Pythonå¼åå¢éæéç¨çBytecodeæ è¯,æ å®é å«ä¹.
pythonä¸ r'', b'', u'', f'' çå«ä¹
1ãå符串å+uï¼å¦u"ææ¯å¼ ä¸"ï¼åç¼u表示该å符串æ¯unicodeç¼ç ï¼å¨Python2ä¸å¸¸è¢«ç¨å¨ä¸æå符çå符串åï¼é²æ¢å 为ç¼ç é®é¢æ导è´çä¹±ç ï¼ä¸è¬å¨æ件å¼å¤´æ æç¼ç æ¹å¼éç¨utf8ãå¨Python3ä¸ï¼ææçå符串é»è®¤é½æ¯unicodeå符串ã
2ãå符串å+rï¼å¦r"\n\n\n\n\n"ï¼
表示ä¸ä¸ªæ£å¸¸çå符串ï¼é常\n被ç¨ä½æ¢è¡ï¼è+råï¼å³è¡¨ç¤º\n\n\n\n\nï¼è¯´ç½äºå°±æ¯å»æåææ ç转ä¹æºå¶ï¼å¨æ®éå符串ä¸ï¼åæ线æ¯è½¬ä¹ç¬¦ï¼ä»£è¡¨ä¸äºç¹æ®çå 容ï¼å¸¸ç¨äºç¹æ®çå符ï¼å¦æ¢è¡ç¬¦ãæ£å表达å¼ãæ件路å¾ã注æä¸è½å¨åå§å符串ç»å°¾è¾å ¥åæ线ï¼å¦åPythonä¸ç¥éè¿æ¯ä¸ä¸ªå符è¿æ¯æ¢è¡ç¬¦(å符串æåç¨\表示æ¢è¡)ï¼ä¼æ¥éã
3ãå符串å+bï¼å¦abc=b'Zhangsan'ï¼
b' 'ï¼è¡¨ç¤ºè¿æ¯ä¸ä¸ªbytes对象ï¼ç¨å¨Python3ä¸ï¼å®é»è®¤çstræ¯unicodeç±»ï¼Python2çstræ¬èº«å°±æ¯bytesç±»ã
b" "ï¼è¡¨ç¤ºåé¢å符串æ¯bytesç±»åã
åç¼b表示该å符串æ¯bytesç±»åï¼å¸¸ç¨å¨ç½ç»ç¼ç¨ï¼æå¡å¨åæµè§å¨åªè®¤bytesç±»åçæ°æ®ï¼å¦sendå½æ°çåæ°årecvçå½æ°çè¿åå¼é½æ¯bytesç±»åã
4ãå符串å+fï¼
Python3.6çæ°å ç¹æ§ï¼åç¼fç¨æ¥æ ¼å¼åå符串ï¼å¯ä»¥çåºfåç¼å¯ä»¥æ´æ¹ä¾¿å°æ ¼å¼åå符串ï¼æ¯format()æ¹æ³çå¯è¯»æ§æ´é«ï¼ä¸ä½¿ç¨è¾æ¹ä¾¿ï¼å¨å ä¸fåç¼åï¼æ¯æå¨å¤§æ¬å·å ï¼è¿è¡Python表达å¼ï¼ä¹å¯ä»¥ç¨fråç¼ç¨æ¥è¡¨ç¤ºåçå符串ã
Bytes.toBytes("str")ä¸"str".getBytes()
æè¿ç¢°å°éè¦å°å符串转为åèç çéæ±ï¼åç°è¿ä¸¤ç§æ¹æ³ç»å¸¸è¢«ä½¿ç¨ï¼é£ä¹å°åºæä»ä¹ä¸åå¢ï¼
æ们ç¨IDEæ¥çä¸ä¸ä¸¤ä¸ªæ¹æ³çæºç
æ以æ们æ¨è使ç¨Bytes.toBytes()æ¹æ³ï¼è¿æ ·å¯ä»¥ææçé¿å å 为个人æ件å符ç¼ç ä¸åè导è´çé®é¢ï¼
javaä¸çwriteBytes()
raf.writeBytesï¼times+""ï¼è¿ä¸ªæ¹æ³éé¢çåæ°æ¯Stringç±»åçètimesæ¯intç±»åç
çä¸ä¸æºç
@SuppressWarnings("deprecation")
public final void writeBytes(String s) throws IOException {
int len = s.length();
byte[] b = new byte[len];
s.getBytes(0, len, b, 0);
writeBytes(b, 0, len);
}