通过Jfilechooser抓住文件时,为什么会失败?

发布于 2025-01-26 16:58:29 字数 1168 浏览 2 评论 0原文

我试图了解Java Swing Guis。因此,我创建了一个简单的GUI来选择一个文件。

当我尝试使用FFMPEG包装器获取文件信息时,我会收到以下错误。

java.io.ioexception:无法运行程序“ c:\ file.mp4”:createProcess错误= 193,%1不是有效的win32应用程序。

我觉得我在这里缺少一些小东西。 谢谢。

JFileChooser fc = new JFileChooser();
int nReturnVal = fc.showOpenDialog(jPanel1);
File fVideo = null;
try {
    if (nReturnVal == JFileChooser.APPROVE_OPTION) {
        fVideo = fc.getSelectedFile();
        //Now you have your file to do whatever you want to do
        jPath.setText(fVideo.getAbsolutePath());
        
        FFprobe ffprobe = new FFprobe(fVideo.getAbsoluteFile().toString());
        FFmpegProbeResult probeResult = ffprobe.probe(fVideo.getAbsolutePath());
        FFmpegFormat format = probeResult.getFormat();
        
        System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs",
                format.filename,
                format.format_long_name,
                format.duration);
        
        jEndTime.setText("" +  format.duration);
        
    } else {
        //User did not choose a valid file
    }
} 
catch (Exception ex) {
    System.out.println(ex.toString());
}

I'm trying to understand Java Swing GUIs. So I created a simple GUI to select a File.

When I attempt to use the FFMPEG wrapper to get file information I get the following error.

java.io.IOException: Cannot run program "C:\File.mp4": CreateProcess error=193, %1 is not a valid Win32 application.

I feel like I'm missing something minor here.
Thanks.

JFileChooser fc = new JFileChooser();
int nReturnVal = fc.showOpenDialog(jPanel1);
File fVideo = null;
try {
    if (nReturnVal == JFileChooser.APPROVE_OPTION) {
        fVideo = fc.getSelectedFile();
        //Now you have your file to do whatever you want to do
        jPath.setText(fVideo.getAbsolutePath());
        
        FFprobe ffprobe = new FFprobe(fVideo.getAbsoluteFile().toString());
        FFmpegProbeResult probeResult = ffprobe.probe(fVideo.getAbsolutePath());
        FFmpegFormat format = probeResult.getFormat();
        
        System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs",
                format.filename,
                format.format_long_name,
                format.duration);
        
        jEndTime.setText("" +  format.duration);
        
    } else {
        //User did not choose a valid file
    }
} 
catch (Exception ex) {
    System.out.println(ex.toString());
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文