简体   繁体   中英

Java application open and play media error on Debian

I am currently working on an application and I wrote it with Java. It is downloading some media files to local computer and open it with a Java method called Desktop.getDesktop().open(file); It is working good on windows but it is not working on debian. Here is used download from url method:

            public String DownloadFromUrlAndGetPath(String DownloadUrl) {
            String fileName="";
            try {
            URL url = new URL(DownloadUrl);
            URLConnection ucon = url.openConnection();
            String raw = ucon.getHeaderField("Content-Disposition");
            // raw = "attachment; filename=abc.mp3"
            if(raw != null && raw.indexOf("=") != -1) {
                fileName = raw.split("=")[1]; //getting value after '='
                fileName = fileName.replace("\"", "").trim();
            } else {
                return "";
            }
            File file = new File(Paths.get(System.getProperty("user.home"), "MyFolderToSaveFiles") +"/"+ fileName);


                InputStream is = ucon.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                ByteArrayBuffer baf = new ByteArrayBuffer(5000);
                int current = 0;
                while ((current = bis.read()) != -1) {
                    try {
                        baf.append((int)((byte)current));
                        continue;
                    }
                    catch (Exception var12_13) {

                    }
                }
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.flush();
                fos.close();

        }
        catch (IOException e) {
            e.getMessage();
        }
    }
    return Paths.get(System.getProperty("user.home"), "MyFolderToSaveFiles") +"/"+ fileName;

Then I want to open that file like that:

File f = new File(url);
Desktop.getDesktop().open(f);

And the error says;

这里的错误

Any suggestion ? Thanks

我使用this解决了这个问题 ,所以当我打开文件时,我使用的是xdg-open。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM