生成的随机字符串怎么能转换成自己想要的输出结果!
import java.io.FileInputStream;import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
public class Demo3 {
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(
new FileOutputStream("E:/xiao.txt"),"UTF-8");
for(int i=0;i<100;i++){
String str = UUID.randomUUID().toString();
osw.write(str);
}
osw.close();
InputStreamReader isr = new InputStreamReader(new FileInputStream("E:/xiao.txt"),"UTF-8");
char c;
while((c=(char)isr.read())!=-1){
c = (char)isr.read();
System.out.print(c);
}
isr.close();
}
}
显示的结果是这样的:6749dbc5-abc8-40b1-b99f-01c7978053e4307814c2-fe32-4ae8-8db5-2ed7cfefd1e124548e18-ce25-4e5f-8d15-5e5ece28f0642ccc250a-6684-4b8d-a93c-a538c4966451fb9f7833-54c6-4541-968d-1a7f53c3b8718f6cda95-9708-4c9d-84f0-decddfe938a78e41dda0-4f2b-4c4b-b511-d48ae240f2ec8f71448d-09b8-47f9-9e42-376cb977027712f47930-33fe-4500-b151-1e75bf9e0f3428496e5f-952c-494b-9f6d-fddcee41a4bedc1e4323-c371-41c6-ba64-148edf1ac82b1341b9af-1845-49d0-9f77-13a15717e0e83f513a67-5282-4f98-bc37-e2376ac61624540a43f2-f024-41b2-865f-996a09b5f53affb25899-0d5a-498b-82e2-e8e8fe7b32bde88365ae-9381-4494-b1c4-3d877fdc53fb538ddb0b-2107-4b21-9908-eb6f4eaec60e75faa2f9-0c07-48dc-b562-e0381485587d64080281-3283-4c58-b9e1-4c75cd22da0d5bb5b370-13b9-4f1f-823d-4ee368eea6c9d6647d1a-11d7-4ad2-9547-02ecdedc4b1dd86771ed-a91f-4389-bf23-1478b9ece4cdb88d5c9b-9a9b-4838-ad63-98ac7588a5e20591224b-719d-4385-902b-b0fc50dd16d0e3f221f6-8d31-450a-838c-.....................
----------------解决方案--------------------------------------------------------
你是想要什么样的输出结果呢
----------------解决方案--------------------------------------------------------
回复 楼主 xiao84699024
就是想要输出正常的字符吧!不要这样的,好乱! ----------------解决方案--------------------------------------------------------
String str = UUID.randomUUID().toString();
在这局下面加个换行符号就行了
----------------解决方案--------------------------------------------------------
你想要什么样的输出结果呢?你要清楚UUID的作用,它就是要随机生成36位的字符串,来防止重复,如果嫌不好看,可以用println换行的
----------------解决方案--------------------------------------------------------
回复 4楼 hhwz
噢,这样的哈!----------------解决方案--------------------------------------------------------
晕,学习了!
----------------解决方案--------------------------------------------------------