Home >Backend Development >PHP Tutorial >PHP compiles and executes Java source files and redirects the output java training java interview questions java3

PHP compiles and executes Java source files and redirects the output java training java interview questions java3

WBOY
WBOYOriginal
2016-07-29 08:53:18956browse
//编译过程:这里必须输入java文件的全路径
exec("javac D:\\test.java");
//运行并重定向输出,这里必须要set classpath,然后重定向的路径也要是全路径
$res = exec("set classpath=D:\\&java test < D:\\in.txt > D:\\out.txt", $out, $status);
//打印出的状态值,如果是0表示成功,1表示失败
var_dump($status);
//如果不是重定向,那么res将会用一个数组来保存
//System.out.println()的输出内容
print_r($res);

test.java源文件如下:

import java.util.*;
public class test
{
	public static void main(String[] args) {
		System.out.println("java php");
		Scanner in = new Scanner(System.in);
		for(int i = 0; i < 10; i++) {
			int n = in.nextInt();
			System.out.println(n);
		}
	}
}

以上就介绍了PHP编译执行Java源文件并重定向输出,包括了java,源文件方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn