package thinking;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* Author: wuche
* Date: 12-4-24
* Time: 上午10:35
*/
public class FatherProcess {
//
// public static void main(String[] args) {
// byte[] b = new byte[1024];
// String cmd ="D:\\java_tools\\jdk1.6.0\\bin\\java -Didea.launcher.port=7544 \"-Didea.launcher.bin.path=D:\\Program Files\\JetBrains\\IntelliJ IDEA 11.0.1\\bin\" -Dfile.encoding=UTF-8 -classpath \"D:\\workspace\\thinking\\bin;D:\\java_tools\\jdk1.6.0\\jre\\lib\\alt-rt.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\charsets.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\deploy.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\javaws.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\jce.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\jsse.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\management-agent.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\plugin.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\resources.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\rt.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\ext\\dnsns.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\ext\\localedata.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\ext\\sunjce_provider.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\ext\\sunmscapi.jar;D:\\java_tools\\jdk1.6.0\\jre\\lib\\ext\\sunpkcs11.jar;D:\\Program Files\\JetBrains\\IntelliJ IDEA 11.0.1\\lib\\junit.jar;D:\\Program Files\\JetBrains\\IntelliJ IDEA 11.0.1\\lib\\idea_rt.jar\" com.intellij.rt.execution.application.AppMain thinking.SubProcess";
// try {
// Process p = Runtime.getRuntime().exec(cmd);
// InputStream is = p.getInputStream();
// ByteArrayInputStream bis = new ByteArrayInputStream(b);
// DataInputStream dis = new DataInputStream(bis);
// int newAge = dis.readInt();
// bis.close();
// dis.close();
// System.out.println("&&&&&&" + newAge);
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
public static void main(String[] args) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String s = "This should end up in the array";
byte buf[] = s.getBytes();
bos.write(buf);
System.out.println("buffer as a string");
System.out.println(bos.toString());
System.out.println("into array");
byte b[] = bos.toByteArray();
for(int i = 0; i<b.length;i++) {
System.out.println((char) b[i]);
}
System.out.println("\\n To an Outputstream()");
OutputStream f2 = new FileOutputStream("text.txt");
bos.writeTo(f2);
f2.close();
System.out.println("Doing a reset");
bos.reset();
for(int i =0;i<3;i++)
bos.write('X');
System.out.println(bos.toString());
}
}
ByteArrayOutputStream
最新推荐文章于 2024-01-05 09:28:19 发布