比较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 ...
随机推荐
- 初学算法之最基础的stl队列
简记为先进先出(first in first out) 它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作. 实用: #include <queue>//头 ...
- codeforces 875B
B. Sorting the Coins time limit per test 1 second memory limit per test 512 megabytes input standard ...
- spring-cloud-netflix-hystrix-dashboard
Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...
- (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585
为梦飞翔 (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585 这里有一个连接,amf0和amf3的库, ...
- Spring(三) Spring IOC 初体验
Web IOC 容器初体验 我们还是从大家最熟悉的 DispatcherServlet 开始,我们最先想到的还是 DispatcherServlet 的 init() 方法.我们发现在 Dispath ...
- SSH Keys vs GPG Keys
SSH Keys vs GPG Keys SSH Keys SSH keys allow you to establish a secure connection between your compu ...
- document.URL vs window.location.href All In One
document.URL vs window.location.href All In One document.URL 与 window.location.href 两者有啥区别 document. ...
- HTTP vs HTTP/2 vs HTTP/3 (QUIC)
HTTP vs HTTP/2 vs HTTP/3 (QUIC) Nginx HTTP/1.1 HTTP/2 HTTP/3 (QUIC) HTTPS 计算机网络协议 OSI 协议簇 (7) TCP/IP ...
- auto embedded component in an online code editor
auto embedded component in an online code editor how to auto open a component in the third parts onl ...
- Flutter: 显示&关闭系统叠加层ui
import 'package:flutter/services.dart'; /// 关闭 SystemChrome.setEnabledSystemUIOverlays([]); /// 显示 S ...