如何在Windows上从命令行运行Java程序?我正在尝试从Windows的命令行执行Java程序。这是我的代码:import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;
import java.io.InputStream;import java.io.OutputStream;public class CopyFile{
public static void main(String[] args)
{
InputStream inStream = null;
OutputStream outStream = null;
try
{
File afile = new File("input.txt");
File bfile = new File("inputCopy.txt");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
System.out.println("File is copied successful!");
}
catch (IOException e)
{
e.printStackTrace();
}
}}我不知道怎么执行这个程序-有什么帮助吗?这在Windows上有可能吗?为什么它与其他环境不同(我以为JVM只编写了一次,在任何地方运行)?
添加回答
举报
0/150
提交
取消