當前位置:首頁 » 操作系統 » linuxtostring

linuxtostring

發布時間: 2022-04-14 16:42:19

linux英文系統,星期一到星期天都是英文顯示,有什麼方式轉換中文

更改環境變數LC_ALL, zh_CN, zh_CN.gb2312, zh_CN.utf8等中文locale
或者可以修改/etc/sysconfig/i18N中的LANG,徹底改成中文界面

❷ 用java如何讀取linux中的某個文件

java是跨平台語言,在linux上讀文件跟在windows上讀文件是一樣的 只是文件路徑不一樣,可以用File對象和FileInputSteam來讀取。但要注意文件編碼問題。
如果有中文請做適當的編碼轉換,通常情況下Linux的默認字元編碼為UTF-8編碼方式,項目可以直接採用utf8編碼方式操作.用System.getProperty("file.encoding")可檢查系統編碼格式。可改操作系統的文件系統編碼,vi /etc/profile,在文件末尾加上
export LANG="zh_CN.GBK"
export LC_ALL="zh_CN.GBK"
編碼轉換代碼:new String(files[i].getName().getBytes("GBK"),"UTF-8");

文件操作的核心代碼請參考下面代碼:

String path= "/home/";
path= "/home/multiverse/Repository/PMEPGImport";
File file=new File(path);
File[] tempList = file.listFiles();
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile()) {
//FileInputStream fis = new FileInputStream("fileName");

//InputStreamReader isr = new InputStreamReader(fis,"utf-8");
StringBuffer buffer = new StringBuffer();
String text;

BufferedReader input = new BufferedReader (new FileReader(tempList[i]));

while((text = input.readLine()) != null)
buffer.append(text +"/n"); }

if (tempList[i].isDirectory()) {
System.out.println("文件夾:"+tempList[i]);
}
}

❸ linux ngettext什麼用

String content=jtextarea1.getText().toString(); String[] a=string.split("\n"); 這樣應該沒問題,用\n不用\n\r是因為android是Unix內核,回車換行是\n

❹ java程序里如何調用linux命令

Java 可以通過 Runtime 調用Linux命令,形式如下:

  1. Runtime.getRuntime().exec(command)

    但是這樣執行時沒有任何輸出,因為調用 Runtime.exec 方法將產生一個本地的進程,並返回一個Process子類的實例(注意:Runtime.getRuntime().exec(command)返回的是一個Process類的實例)該實例可用於控制進程或取得進程的相關信息。

  2. 由於調用 Runtime.exec 方法所創建的子進程沒有自己的終端或控制台,因此該子進程的標准IO(如stdin,stdou,stderr)都通過 Process.getOutputStream(),Process.getInputStream(), Process.getErrorStream() 方法重定向給它的父進程了。

  3. 用戶需要用這些stream來向子進程輸入數據或獲取子進程的輸出,下面的代碼可以取到 linux 命令的執行結果:

    try {

    String[] cmd = new String[]{」/bin/sh」, 「-c」, 」 ls 「};

    Process ps = Runtime.getRuntime().exec(cmd);

    BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));

    StringBuffer sb = new StringBuffer();

    String line;

    while ((line = br.readLine()) != null) {

    sb.append(line).append(」 」);

    }

    String result = sb.toString();

    System.out.println(result);

    } catch (Exception e) {

    e.printStackTrace();

    }

❺ LINUX伺服器如何跑ASP項目

利用mono+xsp架構asp.net環境,可以跑ASP項目
1、 安裝准備(系統安裝忽略)
#安裝完CentOS後,首先更新系統
yum -y update
#然後安裝相關的編譯器和必備的軟體
yum -y install bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel giflib-devel libX11-devel freetype-devel fontconfig-devel cairo-devel libtiff libtiff-devel libjpeg libjpeg-devel giflib giflib-devel libpng libpng-devel libX11 libX11-devel freetype freetype-devel fontconfig fontconfig-devel libexif libexif-devel libXft-devel ghostscript-devel gnome-doc-utils unzip
2 、下載安裝所需要的軟體包
統一下載到/usr/local/src下
wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.tar.bz2
wget http://download.mono-project.com/sources/mono/mono-2.10.8.tar.bz2
wget http://download.mono-project.com/sources/xsp/xsp-2.10.tar.bz2
wget http://download.mono-project.com/sources/mod_mono/mod_mono-2.10.tar.bz2
wget http://apache.fayea.com/apache-mirror//httpd/httpd-2.2.27.tar.gz
3.安裝libgdiplus
libgdiplus是mono中的System.Drawing依賴的一個組件,用於顯示web頁面基本顏色等。
cd /usr/local/src
tar -xjvf libgdiplus-2.10.tar.bz2
cd libgdiplus-2.10
./configure --prefix=/usr/local
make
make install
4.安裝mono
cd /usr/local/src
tar -xjvf mono-2.10.8.tar.bz2
cd mono-2.10.8
./configure --prefix=/usr/local
make
make install
Mono安裝完成之後,可以用命令mono -V查看一下mono的安裝情況,如果能夠看到mono版本號等信息,說明Mono安裝成功。
5.安裝apache
cd /usr/local/src
tar -zxvf httpd-2.2.27.tar.gz
cd httpd-2.2.27
./configure --prefix=/usr/local/apache --enable-mods-shared=most
make
make install
6.安裝mod_mono
cd /usr/local/src
tar -xjvf mod_mono-2.10.tar.bz2
cd mod_mono-2.10
./configure
make
make install
7.安裝xsp
xsp就是mod-mono-server。
安裝之前,先設置一下環境變數
vi /etc/profile #在最後加上下面這句
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
source /etc/profile 或者注銷重新登陸一下
cd /usr/local/src
tar -xjvf xsp-2.10.2.tar.bz2
cd xsp-2.10.2
./configure --prefix=/usr/local
make
make install
8.配置apache
打開/usr/local/apache/conf文件夾中的httpd.conf,這個文件是apache的配置文件,在最後添加
Include /usr/local/apache/conf/mod_mono.conf
將以下#注釋去掉
#ServerName www.example.com:80
在/usr/local/apache/htdocs文件夾中任意創建一個index.aspx文件,添加內容如下
<%@ Page Language="C#" %>
<html>
<head>
<title>hello world</title>
</head>
<body>
<%
for (int i=1; i<=7; i++)
{
Response.Write("<font size=" + i.ToString() + ">");
Response.Write("hello world");
Response.Write("</font><br />");
}
%>
</body>
</html>
當然,你也可以網路,去下載一個asp.net探針
重啟apache
/usr/local/apache/bin/apachectl restart
通過瀏覽器訪問http://IP/index.aspx,測試asp.net環境搭建是否成功,如果返回「hello world」 說明安裝成功

❻ linux 下java讀取配置文件

  1. 如果是相對路徑無論windows還是linux都是一樣的。

  2. 如果是絕對路徑,只需要看好配置文件所在linux的目錄,其他的操作和windows一樣(例如:linux【/usr/local/src/1.config】,windows【c:/1.config】)

  3. 使用File就可以直接讀取了。

❼ 如何把linux伺服器的文件下到本地windows

既然使用了java,實現這種功能就與OS無關了,否則叫什麼跨平台。其實用瀏覽器下載伺服器端文件比較容易:首先,要讓用戶能找到並選擇文件(jsp里實現,部分代碼)StringrealPath=request.getSession().getServletContext().getRealPath("")+"/documents";//項目根目錄下文件路徑FilefileDir=newFile(realPath);String[]fileList=fileDir.list();//返回目錄下文件名稱數組for(inti=0;ifilelength){//最後一次傳送的位元組數byte[]leftpart=newbyte[1024-(int)(totalsize-filelength)];//讀入位元組數組in.readFully(leftpart);//寫入輸出流servletOut.write(leftpart);}else{//讀入1024個位元組到位元組數組bin.readFully(b);//寫和輸出流servletOut.write(b);}}servletOut.close();}/***@paramfileName*@paramfileDownloadType*@paramres*@throwsFileNotFoundException*@throwsIOException*/publicstaticvoidDownload(StringfileName,StringfileDownloadType,HttpServletResponseres)throwsFileNotFoundException,IOException{StringfileContentType=null;if(fileName.endsWith(".doc")){fileContentType="application/msword";}elseif(fileName.endsWith(".pdf")){fileContentType="application/pdf";}elseif(fileName.endsWith(".xls")){fileContentType="application/vnd-ms-excel";}elseif(fileName.endsWith(".txt")){fileContentType="text/plain";}else{fileContentType="application/octet-stream";}longtotalsize=0;//取得要傳輸的文件,實際應用是可以將文件路徑以參數的形式傳入Filef=newFile(fileName);//取文件長度longfilelength=f.length();byte[]b=newbyte[1024];//設置文件輸出流FileInputStreamfin=newFileInputStream(f);DataInputStreamin=newDataInputStream(fin);intpos=fileName.lastIndexOf(java.io.File.separator);Stringfn=newString(fileName.substring(pos+1).getBytes("gb2312"),"ISO8859-1");//設置相應頭信息,讓下載的文件顯示保存信息res.setContentType(fileContentType);res.setHeader("Content-Disposition",fileDownloadType+";filename=\""+fn+"\"");//確定長度Stringfilesize=Long.toString(filelength);//設置輸出文件的長度res.setHeader("Content-Length",filesize);//取得輸出流ServletOutputStreamservletOut=res.getOutputStream();//發送文件數據,每次1024位元組,最後一次單獨計算while(totalsizefilelength){//最後一次傳送的位元組數byte[]leftpart=newbyte[1024-(int)(totalsize-filelength)];//讀入位元組數組in.readFully(leftpart);//寫入輸出流servletOut.write(leftpart);}else{//讀入1024個位元組到位元組數組bin.readFully(b);//寫和輸出流servletOut.write(b);}}servletOut.close();}}

❽ linux和安卓Android中除了某個進程其他後台所有運行的進程殺死命令怎麼寫

使用ActivityManager的killBackgroundProcesses(packageName)方法可以強制性的關閉packageName關聯的執行。這個方法的特點是不可以自殺,只能殺死其他進程。關鍵代碼:
public void onClick(View v) {

String packageName = textPackageName.getText().toString();//獲得包名
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);//獲得獲得管理器
am.killBackgroundProcesses(packageName);//通過包名殺死關聯進程
}

❾ java程序里調用linux命令

1.Java調用shell

Java語言以其跨平台性和簡易性而著稱,在Java裡面的lang包里(java.lang.Runtime)提供了一個允許Java程序與該程序所運
行的環境交互的介面,這就是Runtime類,在Runtime類里提供了獲取當前運行環境的介面。
其中的exec函數返回一個執行shell命令的子進程。exec函數的具體實現形式有以下幾種:
public Process exec(String command) throws IOException
public Process exec(String command,String[] envp) throws
IOException
public Process exec(String command,String[] envp,File dir) throws
IOException
public Process exec(String[] cmdarray) throws IOException
public Process exec(String[] cmdarray, String[] envp) throws
IOException
public Process exec(String[] cmdarray, String[] envp,File dir)
throws IOException

我們在這里主要用到的是第一個和第四個函數,具體方法很簡單,就是在exec函數中傳遞一個代表命令的字元串。exec函數返回的是一個Process類
型的類的實例。Process類主要用來控制進程,獲取進程信息等作用。(具體信息及其用法請參看Java doc)。

1)執行簡單的命令的方法:

代碼如下:

熱點內容
解壓到當前文件夾右鍵 發布:2024-04-26 03:57:08 瀏覽:979
html5android教程視頻下載 發布:2024-04-26 03:09:59 瀏覽:867
伺服器的描述是什麼 發布:2024-04-26 03:08:32 瀏覽:394
個人加密 發布:2024-04-26 03:01:23 瀏覽:521
linuxusbgadget 發布:2024-04-26 02:52:54 瀏覽:304
我的世界空島世界伺服器地址 發布:2024-04-26 01:39:08 瀏覽:248
尼爾機械紀元加密 發布:2024-04-26 01:37:11 瀏覽:868
在控制台輸出sql語句 發布:2024-04-26 01:08:12 瀏覽:432
動畫java 發布:2024-04-26 01:02:40 瀏覽:12
得力文件夾5302 發布:2024-04-26 00:21:32 瀏覽:91