package com.ittx.edi.erp;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class test001 {

public static void main(String[] args) {
try {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("你");

while (stringBuilder.toString().getBytes("utf-8").length < 4194304){ //比较字节是否小于4M
System.out.println(stringBuilder.toString().getBytes("utf-8").length);
stringBuilder.append("你你你你你你你");
}

generateNewText("C:\\temp.txt", stringBuilder.toString());
}catch (Exception ex){

}

}

public static File generateNewText(String filePath, String content) {
try {
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
fileWriter.close();
return file;
} catch (Exception ex) {
return null;
}

}

}

比较String 字符串的字节大小的更多相关文章

  1. String.getBytes()--->字符串转字节数组

    是String的一个方法String的getBytes()方法是得到一个系统默认的编码格式的字节数组getBytes("utf-8") 得到一个UTF-8格式的字节数组把Strin ...

  2. Delphi的字符(Char),字符串(String),字符串指针(PChar),字符数组arrayofchar(来自http://delphi.cjcsoft.net/论坛)

    Delphi有三种类型的字符: AnsiChar这是标准的1字节的ANSI字符,程序员都对它比较熟悉. WideChar这是2字节的Unicode字符. Char在目前相当于AnsiChar,但在De ...

  3. 17.C++-string字符串类(详解)

    C++字符串string类 在C语言里,字符串是用字符数组来表示的,而对于应用层而言,会经常用到字符串,而继续使用字符数组,就使得效率非常低. 所以在C++标准库里,通过类string从新自定义了字符 ...

  4. Java String 字符串操作小结

    // 转载加编辑 -- 21 Apr 2014 1. Java字符串中子串的查找 Java中字符串中子串的查找共有四种方法,如下: 1.int indexOf(String str) :返回第一次出现 ...

  5. string字符串成员函数

    string字符串成员函数 string str1="aaa"; char c='c'; str1.assign("ABCAAAAAAABBBBB");//替换 ...

  6. String字符串性能优化的探究

    一.背景 String 对象是我们使用最频繁的一个对象类型,但它的性能问题却是最容易被忽略的.String 对象作为 Java 语言中重要的数据类型,是内存中占用空间最大的一个对象,高效地使用字符串, ...

  7. ✡ leetcode 165. Compare Version Numbers 比较两个字符串数字的大小 --------- java

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  8. C++主要数据类型在计算机中所占字节大小

    遇到了数据存储的大端和小端问题,这你妹的看的一头雾水,发现我基本知识严重匮乏啊,先了解C++各数据类型在自己机子上占多少字节吧,以及这些数据类型所占字节大小与神马有关.各种查资料然后写代码检验,小结于 ...

  9. C# 整形、双精度浮点型、字符串与字节型的相互转化

    整形.双精度浮点型.字符串与字节型的相互转化,如下 using System; using System.Collections.Generic; using System.Linq; using S ...

随机推荐

  1. PowerShell随笔2---初始命令

    PowerShell便捷之处 PowerShell中兼容运行cmd的命令,比如 ipconfig.ping命令等 PowerShell的命令更友好,可读性更强.比如停止一个服务 CMD命令:sc st ...

  2. 4.PowerShell DSC核心概念之配置

    什么是配置 DSC 配置是定义某一特殊类型函数的 PowerShell 脚本. 配置的语法 Configuration MyDscConfiguration { #配置块 Import-DscReso ...

  3. Zabbix 微信监控报警

    Zabbix-Server 设置 # 使脚本目录生效 [root@zabbix ~]# grep 'script' /etc/zabbix/zabbix_server.conf # AlertScri ...

  4. shiro<1.2.4反序列化分析

    0x01.环境搭建 下载地址:https://codeload.github.com/apache/shiro/zip/shiro-root-1.2.4 环境:Tomcat 8.5.27 + idea ...

  5. infinite scroll blogs

    infinite scroll blogs 无限滚动 blogs beacon api https://www.sitepoint.com/introduction-beacon-api/ Histo ...

  6. Apple 反人类的设计的产品组合

    Apple 反人类的设计的产品组合 Apple shit design macbook pro 2018 + beats solo3 MBP 的耳机孔在电脑右边, betas 的耳机孔在左边, 组合起 ...

  7. DOM & Node.contains

    DOM & Node.contains Node.contains() https://developer.mozilla.org/en-US/docs/Web/API/Node/contai ...

  8. Base 64 & URL & blob & FileReader & createObjectURL

    Base 64 & URL & blob & FileReader & createObjectURL /** * let blob = item.getAsFile( ...

  9. 科普NGK公链生态板块旗下的BGV、SPC、NGK、USDN四大币种

    众所周知,NGK公链所有数据上链.公开透明,NGK公链生态板块目前主要分为四个板块---BGV.SPC.NGK.USDN四大币种,笔者以时间上倒叙手法来一一科普. 首先,是2021新年刚推出的SPC侧 ...

  10. NGK.IO新一代高倍币BGV即将登陆交易所

    据悉NGK.IO新一代高倍币BGV已与全球前十大交易所进行深度恰谈,预计在不久的将来会完成上线计划.此次BGV的上线战略布局,将进一步扩大BGV生态,赋予BGV更多的便利性和发展空间.除此之外,NGK ...