比较String 字符串的字节大小
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 字符串的字节大小的更多相关文章
- String.getBytes()--->字符串转字节数组
是String的一个方法String的getBytes()方法是得到一个系统默认的编码格式的字节数组getBytes("utf-8") 得到一个UTF-8格式的字节数组把Strin ...
- Delphi的字符(Char),字符串(String),字符串指针(PChar),字符数组arrayofchar(来自http://delphi.cjcsoft.net/论坛)
Delphi有三种类型的字符: AnsiChar这是标准的1字节的ANSI字符,程序员都对它比较熟悉. WideChar这是2字节的Unicode字符. Char在目前相当于AnsiChar,但在De ...
- 17.C++-string字符串类(详解)
C++字符串string类 在C语言里,字符串是用字符数组来表示的,而对于应用层而言,会经常用到字符串,而继续使用字符数组,就使得效率非常低. 所以在C++标准库里,通过类string从新自定义了字符 ...
- Java String 字符串操作小结
// 转载加编辑 -- 21 Apr 2014 1. Java字符串中子串的查找 Java中字符串中子串的查找共有四种方法,如下: 1.int indexOf(String str) :返回第一次出现 ...
- string字符串成员函数
string字符串成员函数 string str1="aaa"; char c='c'; str1.assign("ABCAAAAAAABBBBB");//替换 ...
- String字符串性能优化的探究
一.背景 String 对象是我们使用最频繁的一个对象类型,但它的性能问题却是最容易被忽略的.String 对象作为 Java 语言中重要的数据类型,是内存中占用空间最大的一个对象,高效地使用字符串, ...
- ✡ leetcode 165. Compare Version Numbers 比较两个字符串数字的大小 --------- java
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- C++主要数据类型在计算机中所占字节大小
遇到了数据存储的大端和小端问题,这你妹的看的一头雾水,发现我基本知识严重匮乏啊,先了解C++各数据类型在自己机子上占多少字节吧,以及这些数据类型所占字节大小与神马有关.各种查资料然后写代码检验,小结于 ...
- C# 整形、双精度浮点型、字符串与字节型的相互转化
整形.双精度浮点型.字符串与字节型的相互转化,如下 using System; using System.Collections.Generic; using System.Linq; using S ...
随机推荐
- CODE_TEST-- gtest
gtest 提供了一套优秀的 C++ 单元测试解决方案,简单易用,功能完善,非常适合在项目中使用以保证代码质量. https://blog.csdn.net/jcjc918/article/detai ...
- JavaScript常见笔试题分析
1.Javascript的typeof可能返回的结果有哪些? 答:共6种,具体为number ,boolean,string,undefined,function,object(对象或者null返 ...
- ewebeditor 路径
1.关键文件的名称和路径Admin_Login.asp 登录页面Admin_Default.asp 管理首页Admin_Style.aspAdmin_UploadFile.aspUpload.aspA ...
- Ubuntu 编译并执行含opencv的cpp文件
# compilation g++ main.cpp -o main `pkg-config --cflags --libs opencv` # execution ./img-display lin ...
- vue watch route params change
vue watch route params change watch: { '$route.params.menuKey' (val, oldVal) { console.log('new rout ...
- npm publish & 403 Forbidden
npm publish & 403 Forbidden 403 Forbidden - PUT https://registry.npmjs.org/ https://www.npmjs.co ...
- 如何在github中插入图片,链接,图片链接(给图片加上链接),文字+图片链接,的实战分享!
如何在github中插入图片,链接,图片链接(给图片加上链接),文字+图片链接,的实战分享! markdown 1.文字链接: [link-Text](link-URL) [home](https:/ ...
- Android vs iOS vs Web
Android vs iOS vs Web UI view Android ViewGroup ImageView TextView iOS UIView ImageView TextView Web ...
- gitpod & free online ide
gitpod & free online ide Dev Environments as Code for modern DevOps teams. https://www.gitpod.io ...
- HEVC Advance & H.265 专利费
HEVC Advance & H.265 专利费 https://www.hevcadvance.com/pdfnew/HEVC_Advance_Program_Overview_cn.pdf