Linux下讀取文件名亂碼可能的原因是:
1.linux系統默認編碼不支持中文字元
2.文件名本身是亂碼
解決方案是在讀取文件名的時候,要進行顯式的編碼轉換如下:
FileInputStreamfis=newFileInputStream("fileName");
InputStreamReaderisr=newInputStreamReader(fis,"utf-8");
② java在linux下創建文件,中文文件名為亂碼
JBoss4.0.5使用的是tomcat5,而tomcat的默認字元集是ISO-8859-1.找到JBoss的根目錄下名 為\%JBoss4.0.5%server\default\deploy\jbossweb-tomcat55.sar的文件夾.
修改server.xml文件.
修改方法,找到<Connector port="8080"
......>默認是8080埠,在後面加入URIEcoding='UTF-8',字元集根據頁面進行相應的設置,我的整個項目是使用UTF-
8字元集(包括UTF-8).
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
zip包是在windows環境下打的壓縮包,通過java控制在linux環境下解壓之後,解壓出來的文件和文件夾中的中文文件名是亂碼,請問應如何解決
③ java在linux下創建文件,中文文件名為亂碼。請問這個問題是怎麼解決的,謝謝~
修改linux的編碼方式。或者不要命名中文。最好是不要命名為中文
④ java在linux系統下文件夾出現中文亂碼的問題
問題描述:
linux的默認字元編碼是utf-8,在linux上存的是中文名的文件,但是用java讀出來就是亂碼,全是??????然後我通過:new
String(files[i].getName().getBytes("GB2312"),"UTF-8");這樣處理一下,中文文件名全變成了?????,應該怎麼轉碼才能獲取中文?
問題答案:
Java
中的字元編碼默認是Unicode
用new
String(files[i].getName().getBytes("UTF-8"),"UTF-8");試下看對我有幫助
用utf8格式上傳,然後再用utf8格式下載就好了,但是伺服器上存的是亂碼的,遍歷出來是中文的。
⑤ 使用java連接linux,執行shell命令返回值有亂碼,怎麼解決
packagecom.pasier.xxx.util;
importjava.io.IOException;
importjava.io.InputStream;
importjava.nio.charset.Charset;
importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importch.ethz.ssh2.ChannelCondition;
importch.ethz.ssh2.Connection;
importch.ethz.ssh2.Session;
importch.ethz.ssh2.StreamGobbler;
publicclassRmtShellExecutor{
privatestaticfinalLoggerLOG=LoggerFactory.getLogger(RmtShellExecutor.class);
privateConnectionconn;
privateStringip;
privateStringusr;
privateStringpsword;
privateStringcharset=Charset.defaultCharset().toString();
privatestaticfinalintTIME_OUT=1000*5*60;
publicRmtShellExecutor(Stringip,Stringusr,Stringps){
this.ip=ip;
this.usr=usr;
this.psword=ps;
}
privatebooleanlogin()throwsIOException{
conn=newConnection(ip);
conn.connect();
returnconn.authenticateWithPassword(usr,psword);
}
publicStringexec(Stringcmds)throwsIOException{
InputStreamstdOut=null;
InputStreamstdErr=null;
StringoutStr="";
StringoutErr="";
intret=-1;
try{
if(login()){
Sessionsession=conn.openSession();
session.execCommand(cmds);
stdOut=newStreamGobbler(session.getStdout());
outStr=processStream(stdOut,charset);
LOG.info("caijl:[INFO]outStr="+outStr);
stdErr=newStreamGobbler(session.getStderr());
outErr=processStream(stdErr,charset);
LOG.info("caijl:[INFO]outErr="+outErr);
session.waitForCondition(ChannelCondition.EXIT_STATUS,TIME_OUT);
ret=session.getExitStatus();
}else{
LOG.error("caijl:[INFO]ssh2loginfailure:"+ip);
thrownewIOException("SSH2_ERR");
}
}finally{
if(conn!=null){
conn.close();
}
if(stdOut!=null)
stdOut.close();
if(stdErr!=null)
stdErr.close();
}
returnoutStr;
}
privateStringprocessStream(InputStreamin,Stringcharset)throwsIOException{
byte[]buf=newbyte[1024];
StringBuildersb=newStringBuilder();
while(in.read(buf)!=-1){
sb.append(newString(buf,charset));
}
returnsb.toString();
}
publicstaticvoidmain(String[]args){
Stringusr="root";
Stringpassword="12345";
StringserverIP="11.22.33.xx";
StringshPath="/root/ab.sh";
RmtShellExecutorexe=newRmtShellExecutor(serverIP,usr,password);
StringoutInf;
try{
outInf=exe.exec("sh"+shPath+"xn");
System.out.println("outInf="+outInf);
}catch(IOExceptione){
e.printStackTrace();
}
}
}
⑥ java web在Linux上傳輸的亂碼的求解
你本地和LINUX的編碼不一致所導致的亂碼
解決如下:
1、設置request的編碼 new String(request.getParameter("參數名").getBytes("iso-8859-1"), "gbk");
將默認的iso-8859-1轉為gbk 不行的話就多換幾種編碼
2、設置LINUX的編碼
命令行敲入:vi /etc/sysconfig/i18n 修改為以下內容
#LANG="zh_CN.UTF-8"
#SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
#SYSFONT="latarcyrheb-sun16"
#LANG="en_US.UTF-8"
#SUPPORTED="en_US.UTF-8:en_US:en"
#SYSFONT="latarcyrheb-sun16"
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="lat0-sun16"
export LC_ALL="zh_CN.GB18030"
建議如上 不喜勿噴
⑦ java 亂碼恢復
右鍵點擊亂碼文件,選preferenses,看看resource里的編碼是不是正確,如果不是utf-8就改成utf-8,如果是utf-8的話你改成別的編碼試試看看,然後把正常狀態下的內容復制出來,在把文件改成utf-8後把文件復制進去
⑧ 請教java寫入文件亂碼問題,上傳文件將文件寫入到linux路徑下的時候出現亂碼怎麼解決,急~~謝謝
亂碼肯定是亂用編碼造成的,我的建議是上傳之前統一編碼,到linux再用同樣的編碼解碼
⑨ 我在linux系統下,執行java -cp 命令 出現了亂碼 我該腫么辦
你拿遠程工具鏈接,比如putty,securessh,然後在選項裡面改成UTF8就可以了。
⑩ JDK Linux中文亂碼問題
按jhuangjiahua的方法java應用程序的亂碼問題可以解決。<br /><br /><br />標題: <span style="font-weight: bold;">再提 Ubuntu/Debian 下 JAVA 中文顯示</span>
常見的字元轉換方法
將Form 中 的 值 傳 送 到 數 據 庫 中 再 取 出 來 後 全 變 成 了「?」。Form用POST提交數據,代碼中使用了語句:String st=new(request.getParameter(「name」).getBytes(「ISO8859_1」)), 而且也聲明了charset=gb2312。
要處理Form中傳遞的中文參數,應該在JSP中加入下面的代碼,另外定義一個專門解決這個問題的getStr類,然後對接收到的參數進行轉換:
String keyword1=request.getParameter(「keyword1」);
keyword1=getStr(keyword1);
這樣就可以解決問題了,代碼如下:
<%@ page contentType=「text/html;charset=gb2312」%>
<%!
public String getStr(String str){
try{String temp_p=str;
byte[] temp_t=temp_p.getBytes(「ISO8859-1」);
String temp=new String(temp_t);
return temp;
}
catch(Exception e){ }
return 「NULL」;
}
%>
<%--http://www.cndes.com測試--%>
<% String keyword=「創聯網路技術中心歡迎您的到來」;
String keyword1=request.getParameter(「keyword1」);
keyword1=getStr(keyword1);
out.print(keyword);
out.print(keyword1);
%>
2. JDBC Driver的字元轉換
目前大多數JDBC Driver採用本地編碼格式來傳輸中文字元,例如中文字元「0x4175」會被轉成「0x41」和「0x75」進行傳輸。因此需要對JDBC Driver返回的字元以及要發給JDBC Driver的字元進行轉換。當用JDBC Driver向資料庫中插入數據時,需要先將Unicode轉成Native code; 當 JDBC Driver從資料庫中查詢數據時,則需要將Native code轉換成Unicode。下面給出了這兩種轉換的實現:
String native2Unicode(String s) {
if (s == null || s.length() == 0) {
return null;
}
byte[] buffer = new byte[s.length()];
for (int i = 0; i s.length(); i++) { if (s.charAt(i)>= 0x100) {
c = s.charAt(i);
byte []buf = (「」+c).getBytes();
buffer[j++] = (char)buf[0];
buffer[j++] = (char)buf[1];
}
else {buffer[j++] = s.ch
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=377091