日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

java用log.i打印数组_java-使用JSCH将ssh日志打印到列表(android)

發布時間:2023/12/4 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java用log.i打印数组_java-使用JSCH将ssh日志打印到列表(android) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我一直試圖通過將包含我目錄名稱的log.i字符串值添加到數組中,然后使用數組適配器通過listView打印它們,來在listView中的目錄中打印項目.但是,當我嘗試運行該應用程序時,它將打印包含目錄名稱的日志,但不會在listView上打印任何內容.有什么幫助嗎?

這是我的代碼:

import android.os.AsyncTask;

import android.os.Bundle;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.util.ArrayList;

import java.util.Properties;

import android.view.Menu;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import com.jcraft.jsch.Channel;

import com.jcraft.jsch.JSch;

import com.jcraft.jsch.Session;

import android.app.Activity;

import android.util.Log;

import android.widget.ListView;

import android.widget.Toast;

public class MainActivity extends Activity {

private String user = "root"; //username

private String pass = "password"; //password

private String host = "hostname"; //hostname

private int portNum = 22; //replace port number

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

new AsyncTask() {

@Override

protected Void doInBackground(Integer... params) {

try {

executeRemoteCommand(user, pass, host, portNum);

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

}.execute(1);

}

public String executeRemoteCommand(String username, String password, String hostname, int port)

throws Exception {

//declare list and array

final ListView list = (ListView)findViewById(R.id.choose_sound_listView);

ArrayList soundNames = new ArrayList();

JSch jsch = new JSch();

Session session = jsch.getSession(username, hostname, port);

session.setPassword(password);

// Avoid asking for key confirmation

Properties prop = new Properties();

prop.put("StrictHostKeyChecking", "no");

session.setConfig(prop);

session.connect();

Channel channel = session.openChannel("shell");

channel.connect();

DataInputStream dataIn = new DataInputStream(channel.getInputStream());

DataOutputStream dataOut = new DataOutputStream(channel.getOutputStream());

// send ls command to the server

dataOut.writeBytes("ls

");

dataOut.flush();

// and print the response

String line = dataIn.readLine();

String out = line + "

";

// loop to add log string values to array

for (int i = 0; i < 10; i++) {

line = dataIn.readLine();

out += line + "

";

Log.i("SSH", ": " + line);

//add to array

soundNames.add(line);

}

ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1, android.R.id.text1

, soundNames);

list.setAdapter(adapter);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView> arg0, View arg1,

int position, long arg3) {

// Show Alert

Toast.makeText(getApplicationContext(),

"Alert", Toast.LENGTH_LONG)

.show();

}

});

dataIn.close();

dataOut.close();

channel.disconnect();

session.disconnect();

return out;

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}

}

總結

以上是生活随笔為你收集整理的java用log.i打印数组_java-使用JSCH将ssh日志打印到列表(android)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。