参考链接
http://blog.csdn.net/zhuyijian135757/article/details/37706437
http://blog.csdn.net/elia1208/article/details/6329428
http://blog.csdn.net/huoyunshen88/article/details/25896677
http://code-chris.iteye.com/blog/365157
1.tomcat环境中file.encoding引发的思考
编码问题总结:
linux 系统默认编码utf-8
修改和查看linux编码问题:
[html] view plaincopy在CODE上查看代码片派生到我的代码片
[root@test-1 ~]# vi /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
linux默认编码UFT-8,终端输出默认编码自然是UTF-8,window中使用secureCRT默认编码是GBK,
链接到linux系统输出乱码,因为Linux默认是utf-8,所以把secureCRT的默认编码修改为utf-8就ok。
WINDOWS 默认编码GBK
了解了系统平台的的编码,才容易解决编码问题。
WIN7中tomcat启动的控制台默认编码是GBK,一般软件默认采用系统默认字符集。
tomcat的应用一般常用的国际编码是utf-8,应用输出采用系统默认编码GBK,
所以乱码,再启动jvm时设置成-Dfile.encoding="UTF-8",应用乱码问题解决。
file.encoding默认的字符集跟操作系统有关,中文操作系统下面默认的字符集是GBK,如果流程定义的xml文件中用UTF-8,
则不能正确转换,所以需要修改file.encoding的值为UTF-8。
部署在tomcat中的文件要修改file.encoding的值,可以在tomcat的catalina.bat文件中set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%的后面加上 -Dfile.encoding="UTF-8"
java File_encoding属性
windows下一般是GBK. 指定编码方式也很简单, java -Dfile.encoding=utf-8 xxxx (需要执行的class文件)
下面来看下 file.encoding 这个属性的英文解释.
This property is used for the default encoding in Java, all readers and writers would default to use this property. “file.encoding” is set to the default locale of
Windows operationg system since Java 1.4.2. System.getProperty(“file.encoding”) can be used to access this property. Code such as System.setProperty(“file.encoding
”, “UTF-8”) can be used to change this property. However, the default encoding can not be changed dynamically even this property can be changed. So the conclusion
is that the default encoding can’t be changed after JVM starts. “java -Dfile.encoding=UTF-8” can be used to set the default encoding when starting a JVM. I have
searched for this option Java official documentation. But I can’t find it.
大致的意思主要下面几点:
1. java内所有的reader和 writer操作默认都是用 file.encoding这个系统属性作为编码方式的,看代码:
[java] view plaincopy
//way1
String html1="<html>...</html>";
FileWriter writer1=new FileWriter(new File("C:\\xxxx.html"));
writer1.write(html1);
writer1.close();
//way2
String html2="<html>...</html>";
OutputStreamWriter writer2=new OutputStreamWriter(new FileOutputStream
(new File("C:\\xxxx.html")),"utf-8");
writer2.write(html2);
writer2.close();
第一种方法默认会用 file.encoding 这个属性对文件进行编码,然后输出.一旦你执行class文件的时候没有指定该属性, 默认就会用操作系统本身编码方式,如gbk等.
第二种方式指定了文件编码方式,并输出.
偶项目中的遇到异常就是由第一种方法导致的,刚开始我用第二种方式去解决的,但是这只能解决这一地方,其他没发现的就不好解决了. 更好的解决,看注意点2.
2.JVM启动之前如果未指定file.encoding这个属性,这个属性就会默认为操作系统编码方式, JVM启动如果指定了file.encoding这个属性,整个项目都会用这个属性
作为reader和writer操作的默认编码方式,并且在一个运行的应用程序中
file.encoding的值只有一个,并且值为入口函数的保存编码的值,不会被后面的覆盖。
so,解决问题最好的方式就是在启动项目时就知道file.encoding这个属性,后续的读写操作没有特殊编码需要的划,都可以继承过来使用.
相关推荐
主要介绍了java 中file.encoding的设置详解的相关资料,需要的朋友可以参考下
编程人员在一定的操作系统上选择一个合适的编辑软件来实现源程序代码并以.java扩展名保存在操作系统中,例如我们在中文win2k中用记事本编辑一个java源程序;...要查看系统的file.encoding参数,可以用以下
一个进行文件编码的jar包,使用方式就像jstl一样的,页面进行地址短编码很方便。
将指定的字符串追加到文件中,如果文件还不存在则创建该文件。 public static void AppendAllText(string path, string contents); public static void AppendAllText...using (Stream s = File.Create(filePath)) {
FileEncodingConverter 文件编码转换工具 非常好用!
Windows下默认的是GBK,但我们程序一般IO流中字符编码一般都设置的是utf-8,这样会导致中文乱码。因此需要修改file.encoding为UTF-8.如果应用容器是tomcat,可参考如下修改方法
修改cmd_default=javaw -Dfile.encoding=#fileEncoding# -Xmx#maxheap# -classpath "#wekajar#;#cp#" #mainclass# 为cmd_default=javaw -Dfile.encoding=#fileEncoding# -Xmx#maxheap# -classpath "#wekajar#;#cp#;...
Encoding.Default、Encoding.UTF8、Encoding.GetEncoding("GBK") 输出Encoding.GetEncodings(),所有编码。什么是文本文件。拖到记事本中还能看得懂的就是文本文件,doc不是。 File类的常用静态方法: (FileInfo*...
StreamWriter file = new StreamWriter(fso, System.Text.Encoding.GetEncoding("GB2312")); file.Write("aaaaaaaaaa"); file.Flush(); file.Close(); fso.Close(); string path1 = ...
检测文件编码和语言功能性确定任何文本文件的编码和语言!检测34种语言以及适当的编码大量输入时... // app.jsconst languageEncoding = require ( "detect-file-encoding-and-language" ) ;document . getElementById
idea actiBPM插件 安装问题 ...2. After start IDEA, set Settings—>Editor—>File Encodings to UTF-8 如果上述操作引起idea console日志中文乱码 可设置服务器启动参数:-Dfile.encoding=UTF-8
一个用游程编码实现对BMP文件的压缩,收藏。
vs FileEncoding插件 支持2019,2022
Encoding for XML files has been added. 3. The error occurred on exporting data into XLSX with custom export source and AutoCalcColWidth property set to True. Fixed now. 4. Invalid XLS file ...
默认: 读取huffman_test_file.txt---> 编码 ---> 生成huffman_encoding_file.txt 读取huffman_encoding_file.txt ---> 译码 ---> 生成huffman_decoding_file.txt 2.我将一些测试健壮性的开关宏设置在了开头,方便...
<filter-name>Encoding <filter-class>com.jkx.demo.cn.Encoding</filter-class> <filter-name>Encoding <url-pattern>/index.jsp <welcome-file-list> <welcome-file>index.jsp</welcome-file>...
var errorOrNames = attributesNamesAtPath("/file.txt") if let names = errorOrNames.names { names.map { println($0) } } else { println(errorOrNames.error) } > com.apple.FinderInfo >...
textFile = new StreamReader(txtPath, Encoding.GetEncoding("gb2312")); } string[] result; if (textFile != null) { char[] sp = new char[] { '\r', '\n' }; string tValues = textFile....
The format of a STEP-File is defined in ISO 10303-21 Clear Text Encoding of the Exchange Structure.[1] ISO 10303-21 defines the encoding mechanism on how to represent data according to a given ...
2、在IDEA中设置File——》Settings——》Build, Execution, Deployment——》Runner——》VM Options后的输入框设置-DarchetypeCatalog=internal 3、注意在File——》Other Settings——》Default Settings中也要...