根据小写26个字母,随机生成单词,乱文
根据小写26个字母,随机生成单词,乱文
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;/*** @author Mxhlin* @Email fuhua277@163.com* @Date 2022/09/22/19:27* @Version* @Description 根据小写26个字母,随机生成单词,乱文*/
public class OutputStreamDemo {public static void main(String[] args) {Random rand = new Random();try (FileOutputStream fos = new FileOutputStream("木.txt")){for (int i = 0; i < 100; i++) {fos.write(randStr(rand.nextInt(2,20)).concat("\t\n").getBytes());}} catch (FileNotFoundException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}public static String randStr(int n) {Random rand = new Random();String letter = "abcdefghijklmnopqrstuvwsyz";StringBuilder sb = new StringBuilder();for (int i = 0; i < n; i++) {StringBuilder sb1 = new StringBuilder();int len = rand.nextInt(2,10);// 随机单词的长度for (int j = 0; j < len; j++) {// 给单词赋值sb1.append(letter.charAt(rand.nextInt(letter.length())));}sb1.append(" ");// 后面添加空格String ts = new String(sb1);if (i ==0 ){// 首字母大写ts = ts.substring(0,1).toUpperCase().concat(ts.substring(1));}else if (i == n-1){// 结尾符号ts = ts.substring(0,ts.length()-1)+"!.?".charAt(rand.nextInt(3));}sb.append(ts);}return sb.toString() ;}
}
识别一个文件的真实格式
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;/*** @author Mxhlin* @Email fuhua277@163.com* @Date 2022/09/22/19:52* @Version* @Description 识别一个文件的真实格式*/
public class Ex3 {public static void main(String[] args) {HashMap<String, String> map = new HashMap<>();map.put(".jpg","ffd8ffe0");map.put(".7z","377abcaf");map.put(".zip","504b34");map.put(".txt","aced05");System.out.println(map.containsKey(".7z"));System.out.println(getHeader(new File("D:\\IOTest\\112\\112.7z"), 4));String type = getType(new File("D:\\IOTest\\112\\112.7z"));System.out.println(type);// File file = new File("D:\\IOTest\\112");// File[] files = file.listFiles();// for (File file1 : files){// String name = file1.getName();// String hou = name.substring(name.lastIndexOf(".")).toLowerCase();// System.out.printf("%s : %s : %s %n",name,hou,getHeader(file1,4));// }}public static String getType(File file){HashMap<String, String> map = new HashMap<>();map.put("ffd8ffe0",".jpg");map.put("377abcaf",".7z");map.put("504b34",".zip");map.put("aced05",".txt");String header = getHeader(file, 4);if (map.containsKey(header)){return map.get(header);}else {return "未知文件";}}public static String getHeader(File file,int n){String header = "";if (file.isFile()){try (FileInputStream fis = new FileInputStream(file)){byte[] bytes = new byte[n];fis.read(bytes);StringBuilder sb = new StringBuilder();for (byte byt : bytes){sb.append(String.format("%x",byt));}header = sb.toString();} catch (FileNotFoundException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}return header;}
}
指定一个目录下所有的java文件,把里面的内容格式化输出在md文件
import java.io.*;/*** @author Mxhlin* @Email fuhua277@163.com* @Date 2022/09/22/17:08* @Version* @Description 指定一个目录下所有的java文件,把里面的内容格式化输出在md文件*/
public class AllCodeDemo {static int sum= 0 ;public static void main(String[] args) {all(new File("D:\\peixun\\java\\Lx"));}public static void all(File file){if (file.isDirectory()){File[] files = file.listFiles();for (File file1 : files) {if (file1.isDirectory()) all(file1);if (file1.isFile()&&file1.getName().endsWith(".java")){all(++sum,file1,new File("木.md"));}}}if (file.isFile()&&file.getName().endsWith(".java")){all(++sum,file,new File("木.md"));}}public static void all(int n, File src,File dst){String template = """%d %s (%d行 %tF %<tT)```java%s```""";try (FileInputStream fis = new FileInputStream(src); FileOutputStream fos = new FileOutputStream(dst,true)){// 根据上面的参数 格式化sum = n;String path = src.getAbsolutePath();String s = new String(fis.readAllBytes());long count = s.lines().count();long l = src.lastModified();String format = String.format(template, sum, path, count, l, s);fos.write(format.getBytes());fos.flush();} catch (FileNotFoundException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}
}
根据小写26个字母,随机生成单词,乱文相关推荐
- [No00003E]26个字母暗藏的单词秘密
26个字母暗藏的单词秘密 人们普通认为:英语是拼音文字,因而与象形无关.但是,实际上,即使作为拼音文字,其字母的来源也与象形有关.根据笔者十多年的研究结果,英语中的二十六个字母每个字母都有其象形意义, ...
- c语言随机产生大写字母,随机生成指定长度字符字符串(C语言实现)
相关函数 srand(), rand() 头文件 #include 定义函数 int rand(void) 函数说明 rand()会返回一随机数值,范围在0至RAND_MAX 间.在调用此函数产生随机 ...
- java字母随机生成_java生成随机字母
方法一: public class RandomTest extends TestCase { public void testRandom1() throws Exception { String ...
- Python育儿系列-python英文字母随机生成
小孩子需要学习认识英文字母和大小写,这个程序是用来生成考核用的英语字母大小写的一个小程序 # -*- coding: utf-8 -*- # @Time : 2019-01-07 00:07 # @A ...
- 随机产生单词然后判别其是否是真正的(可拼写的)单词:)
linux下带的好玩小巧的东东就是多啊!本猫又找到一个spell程序,如果单词是可拼写的则神马也不输出,否则输出疑似拼错的单词.可以把若干单词放在文件中,也可以用管道输入spell.为了简便本猫采用了 ...
- //随机生成1位大写字母\小写字母\数字
package HomeWork; //随机生成1位大写字母\小写字母\数字 public class Test_2 {public static void main(String[] args) { ...
- python随机密码生成在26个字母中随机生成10个_习题6:二.3 随机密码生成
编写程序在26个字母大小写和9个数字组成的列表中随机生成10个8位密码. import random num_ls = [] # 创建数字.小写字母.大写字母空列表 str_ls = [] STR_l ...
- java实现:随机生成小写字母,并判断是元音还是辅音
java实现: 随机生成小写字母,并判断是元音还是辅音 用switch进行判断,然后把switch放入for循环 package com.word.word;//随机生成小写字母,并判断是元音还是辅音 ...
- 小知识:随机生成26个字母中(一个或多个)的字母
小知识:就直接上代码了,不多说 String str = "";for (int i = 0;i<1;i++){str = str+ (char)(Math.random() ...
最新文章
- java进阶 线程池 join用法总结:thread4.join();方法,就表明thread4.join();这个线程受到贵客待遇,直到这个线程执行完,被插入这个方法的载体线程才可以执行。
- 鸿蒙可胜安卓,【鸿蒙币谈】币圈投资中八大见顶信号,让你抓住最佳买卖机会!...
- java的知识点11——面向对象的三大特征之一继承、instanceof 运算符、方法的重写override、Object类基本特性、toString方法
- scala把序列分解成子集(group by,partition)
- windows+PHP+shell_exec()无法执行的原因
- 推荐系统遇上深度学习(十一)--神经协同过滤NCF原理及实战
- 立即生效!英特尔 CEO 从云计算巨头 VMware 卸任
- 路由器NAT负载均衡实验过程详解
- 基于java的房地产客户管理系统
- 元宇宙的时代来不及解释了快上车
- 一、二线城市 IT 公司大盘点!建议收藏
- 图像处理-RGB24转YUV420遇到的坑以及执行效率对比
- SCCM更新卡住恢复处理方法
- mac 打开网页慢_Safari打开网页卡住或加载极慢问题解决方案
- 跳舞的小人 和 盲文
- 希腊字母读音及其latex输入
- BZOJ 4946: [Noi2017]蔬菜 模拟费用流
- maven命令的方式
- java与sqlserver 2008_Java连SqlServer 2008
- CLOUD云计算进阶(三)-云平台部署与管理