guanking19

问题描述:现在在我的F盘下面有个notepad.txt文件,我希望通过java程序将他以记事本的形式打开

实现思路:使用java的runtime.getruntime.exec(String[] args)来调用0命令行实现。代码如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		args = new String[3];
		args[0] = "cmd";
		args[1] = "/k";
		args[2] = "notepad.exe F:/notepad.txt";
		Process process = Runtime.getRuntime().exec(args);
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				process.getInputStream()));
		char buf[] = new char[1024];
		while (reader.read(buf) != -1) {
			System.out.println(new String(buf));
		}
		reader.close();
		System.out.println("finish!");
	}
}

  转载请注明出处!!!

分类:

技术点:

相关文章:

  • 2021-11-09
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-12-14
  • 2022-01-31
猜你喜欢
  • 2022-02-12
  • 2021-11-09
  • 2021-06-01
  • 2021-11-19
  • 2021-07-29
  • 2021-11-03
  • 2022-12-23
相关资源
相似解决方案