这是一个运行记事本程序并粘贴存储在该程序本身中的特定文本的java程序代码....
我想知道您是否可以向我解释String vbs
值,以及.File file
和. 如果你很慷慨,请向我解释整个代码。("cscript //NoLogo " + file.getPath())
Process p
我是 Java 的初学者,不完全是,但如果你想从 0 到 10 来判断,我会是 1.5/10
import java.io.File;
import java.io.FileWriter;
import javax.swing.JTextField;
public class PasteToNotepad {
public static void main(String[] args) throws Exception {
String text = "Some text for testing.";
JTextField textField = new JTextField(text);
textField.setSelectionStart(0);
textField.setSelectionEnd(text.length() - 1);
textField.copy();
String vbs = ""
+ "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
+ "WshShell.Run \"notepad\", 9\n"
+ "WScript.Sleep 500\n"
+ "WshShell.SendKeys \"^V\"";
File file = File.createTempFile("PrintDialog", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
p.waitFor();
}
}