博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Java中哪里可以获得“UTF-8”字符串文字?
阅读量:2292 次
发布时间:2019-05-09

本文共 1104 字,大约阅读时间需要 3 分钟。

本文翻译自:

I'm trying to use a constant instead of a string literal in this piece of code: 我试图在这段代码中使用常量而不是字符串文字:

new InputStreamReader(new FileInputStream(file), "UTF-8")

"UTF-8" appears in the code rather often, and would be much better to refer to some static final variable instead. "UTF-8"经常出现在代码中,而且更好地引用一些static final变量。 Do you know where I can find such a variable in JDK? 你知道我在JDK哪里可以找到这样一个变量吗?

BTW, on a second thought, such constants are bad design: 顺便说一句,第二个想法,这样的常量是糟糕的设计:


#1楼

参考:


#2楼

现在我使用来自 org.apache.commons.lang3.CharEncoding.UTF_8常量。


#3楼

这个常量在类org.apache.commons.codec.CharEncoding中也可用(其中包括: UTF-16US-ASCII等)。


#4楼

如果此页面出现在某些Web搜索中,从Java 1.7开始,您现在可以使用来访问标准字符集的常量定义。


#5楼

In Java 1.7+, defines constants for Charset including UTF_8 . 在Java 1.7+中, 定义了Charset常量,包括UTF_8

import java.nio.charset.StandardCharsets;...StandardCharsets.UTF_8.name();

For Android: minSdk 19 对于Android:minSdk 19


#6楼

If you are using for Java/Android you can use the following constant: 如果您使用 for Java / Android,您可以使用以下常量:

import com.squareup.okhttp.internal.Util;Util.UTF_8; // CharsetUtil.UTF_8.name(); // String

转载地址:http://svcnb.baihongyu.com/

你可能感兴趣的文章
Using Bootchart on Android
查看>>
Android Logging System
查看>>
The System Server in Android
查看>>
Android Zygote Startup
查看>>
Android Architecture
查看>>
Debugging Android JNI with CheckJNI
查看>>
Python开发工具 Wing IDE
查看>>
ARM微处理器的指令集概述(三)—— .word的含义
查看>>
uboot-2011.12移植到S3C2440(序二)—— binutils二进制工具集与u-boot
查看>>
uboot-2011.12移植到S3C2440(序一)——ELF可执行文件及其组成
查看>>
Android JIT带来的虚拟机崩溃问题及解决方案
查看>>
Dalvik——如何控制vm
查看>>
ARM微处理器的指令集概述(四)——MOV和LDR的区别
查看>>
uboot-2011.12移植到S3C2440(三)——硬件初始化:看门狗、中断、时钟
查看>>
uboot-2011.12移植到S3C2440(四序)——SDRAM分析
查看>>
uboot-2011.12移植到S3C2440(三序)——MMU Cache/TLB/etc on/off functions
查看>>
S3C2440 uboot移植系列教程
查看>>
vim与CTAGS查看头文件
查看>>
uboot-2011.12移植到S3C2440(四)——SDRAM初始化之后,卡在board.c的memset不动
查看>>
移植u-boot-2010.09到S3C2440(一)——硬件初始化与测试
查看>>