谁能告诉我为什么这个 c# 控制台命令不能在 Java 上运行?
我制作了一个 C# 控制台程序,如下所示:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace face
{
class Program
{
public static void Main(string[] args)
{
String path = args[0];
byte[] imageBytes = File.ReadAllBytes(path);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
Bitmap S1 = new Bitmap(image);
Console.WriteLine(S1.GetPixel(2, 10));
}
}
}
当我运行 Program.exe image.jpg
时,我得到:
Color [A=255, R=128, G=32, B=128]
然后我创建了一个简单的 Java 应用程序来运行 Program.exe
可执行文件:
class project
{
public static void main(String[] args)
{
String comman="C:\\WINXP\\system32\\Program.exe Sunset.jpg";
try
{
Process process = Runtime.getRuntime().exec(comman);
System.out.println(process.getOutputStream());
} catch (Exception e)
{e.printStackTrace(System.err);}
}
}
当我尝试运行 Java 应用程序时,出现以下错误:
Program.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
最佳答案
你可能想改变
String comman = "C:\\WINXP\\system32\\Program.exe Sunset.jpg";
到
String[] comman = { "C:\\WINXP\\system32\\Program.exe", "Sunset.jpg" };
关于c# - 为什么 c# 控制台命令不在 java 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8223946/