I'm trying to execute a Java program from the command line in Windows.
(我正在尝试从Windows中的命令行执行Java程序。)
Here is my code: (这是我的代码:)
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();
}
}
}
I'm not sure how to execute the program - any help?
(我不确定如何执行程序-有帮助吗?)
Is this possible on Windows? (在Windows上可以吗?)
Why is it different than another environment (I thought JVM was write once, run anywhere)? (为什么它不同于另一个环境(我以为JVM只写一次,可以在任何地方运行)?)
ask by Elizabeth Turner translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…