java调用其它程序之返回值
2008-01-22 22:44
483 查看
Process process = Runtime.getRuntime().exec("cmd /c dir");
System.out.println(loadStream(process.getInputStream())); //load the stream
System.out.println(loadStream(process.getErrorStream())); //load the stream
static String loadStream(InputStream in) throws IOException
{
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while ( (ptr = in.read()) != -1)
{
buffer.append( (char) ptr);
}
return buffer.toString();
}
---------------------------
刚才那个loadStream方法,如果dir里面有汉字则显示为乱码。应将该方法修改为如下:
static String loadStream(InputStream in) throws IOException
{
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while ( (ptr = in.read()) != -1)
{
buffer.append( (char) ptr);
}
String aa=buffer.toString();
byte[] temp= aa.getBytes("ISO-8859-1");
String result=new String(temp);
return result;
}
System.out.println(loadStream(process.getInputStream())); //load the stream
System.out.println(loadStream(process.getErrorStream())); //load the stream
static String loadStream(InputStream in) throws IOException
{
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while ( (ptr = in.read()) != -1)
{
buffer.append( (char) ptr);
}
return buffer.toString();
}
---------------------------
刚才那个loadStream方法,如果dir里面有汉字则显示为乱码。应将该方法修改为如下:
static String loadStream(InputStream in) throws IOException
{
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while ( (ptr = in.read()) != -1)
{
buffer.append( (char) ptr);
}
String aa=buffer.toString();
byte[] temp= aa.getBytes("ISO-8859-1");
String result=new String(temp);
return result;
}
相关文章推荐
- Java程序调用带参数的shell脚本返回值
- java调用其它程序之记事本
- java 调用其它程序
- 从java程序中调用其它程序
- java程序调用Oracle 存储过程 获取返回值(无返回,非结果集,结果集)
- 从java程序中调用其它程序
- Java程序调用带参数的shell脚本返回值
- 从java程序中调用其它程序
- Java程序调用带参数的shell脚本返回值
- excel中vba调用java程序并获取返回值
- 使用bat命令或shell脚本调用java程序
- java中的JNI调用其他开与语言的程序
- Java通过JNI调用C++程序
- Java程序调用kettle中的job(.kjb)和Trans(.ktr)
- JavaScript调用客户端Java程序的方法
- java程序调用kettle
- init.rc文件里面启动c++程序,通过jni调用java实现
- Birt报表调用java程序
- JAVA调用外部程序阻塞问题
- 在JAVA与JSP中要调用一个LINUX上的脚本程序,或WINDOWS上的脚本程序