如何给eclipse设置字符集
1个回答
2016-06-19 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
method 1: 你可以在java里面调用cmd,就可以执行了
method 2: 还没有想到.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
public class Command {
private java.lang.Process p;
private InputStream is;
private OutputStream os;
private BufferedWriter bw;
private BufferedReader br;
private ProcessBuilder pb;
private InputStream stdErr;
public Command() {
}
//获取Process的输入,输出流
public void setCmd(String cmd) {
try {
p = Runtime.getRuntime().exec(cmd);
os = p.getOutputStream();
is = p.getInputStream();
stdErr = p.getErrorStream();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
//向Process输出命令
public void writeCmd(String cmd) {
try {
bw = new BufferedWriter(new OutputStreamWriter(os));
bw.write(cmd);
bw.newLine();
bw.flush();
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//读出Process执行的结果
public String readCmd() {
StringBuffer sb = new StringBuffer();
br = new BufferedReader(new InputStreamReader(is));
String buffer = null;
try {
while ((buffer = br.readLine()) != null) {
sb.append(buffer + "\n");
}
System.out.println(p.waitFor());
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
//将命令一股脑塞入list中
public LinkedList<String> doCmd(LinkedList<String> lists) {
LinkedList<String> list = new LinkedList<String>();
for (String s : lists) {
writeCmd(s);
list.add(readCmd());
}
return list;
}
public static void main(String[] args) {
Command cmd = new Command();
cmd.setCmd("cmd");
//cmd.writeCmd("mysql -uroot -p1234");
//cmd.writeCmd("set character_set_server = 'gbk'");
//System.out.println(cmd.readCmd());
LinkedList<String> list = new LinkedList<String>();
list.add("mysql -uroot -p1234");
list.add("set character_set_server = 'gbk'");
list = cmd.doCmd(list);
for(String s:list){
System.out.print(s);
}
}
}
method 2: 还没有想到.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
public class Command {
private java.lang.Process p;
private InputStream is;
private OutputStream os;
private BufferedWriter bw;
private BufferedReader br;
private ProcessBuilder pb;
private InputStream stdErr;
public Command() {
}
//获取Process的输入,输出流
public void setCmd(String cmd) {
try {
p = Runtime.getRuntime().exec(cmd);
os = p.getOutputStream();
is = p.getInputStream();
stdErr = p.getErrorStream();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
//向Process输出命令
public void writeCmd(String cmd) {
try {
bw = new BufferedWriter(new OutputStreamWriter(os));
bw.write(cmd);
bw.newLine();
bw.flush();
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//读出Process执行的结果
public String readCmd() {
StringBuffer sb = new StringBuffer();
br = new BufferedReader(new InputStreamReader(is));
String buffer = null;
try {
while ((buffer = br.readLine()) != null) {
sb.append(buffer + "\n");
}
System.out.println(p.waitFor());
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
//将命令一股脑塞入list中
public LinkedList<String> doCmd(LinkedList<String> lists) {
LinkedList<String> list = new LinkedList<String>();
for (String s : lists) {
writeCmd(s);
list.add(readCmd());
}
return list;
}
public static void main(String[] args) {
Command cmd = new Command();
cmd.setCmd("cmd");
//cmd.writeCmd("mysql -uroot -p1234");
//cmd.writeCmd("set character_set_server = 'gbk'");
//System.out.println(cmd.readCmd());
LinkedList<String> list = new LinkedList<String>();
list.add("mysql -uroot -p1234");
list.add("set character_set_server = 'gbk'");
list = cmd.doCmd(list);
for(String s:list){
System.out.print(s);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询