【问题标题】:Difficult on accessing a video's directory难以访问视频目录
【发布时间】:2014-05-13 15:39:44
【问题描述】:

你好,我在面板上播放了一个视频

我通过这个得到视频的网址:

URL urlWaterIntake = new URL("file:///c:/tmp/water.avi");

但是我将 'tmp' 文件夹移到了 eclipse IDE 的 'bin' 文件夹中,现在 我通过这个访问:

URL urlWaterIntake = new URL("file:///tmp/water.avi");

和错误!瞧!什么样的生活……,一些解决方案??

顺便说一句,我也试过这个:

File myFile = new File("tmp/water.avi");
URL urlWaterIntake = new URL(myFile.toURI().toURL());

但没有任何效果.....

【问题讨论】:

  • 您是在 Applet 内部还是在 JSP 内部或其他任何地方使用它?
  • 可能的解决方案:stackoverflow.com/a/3209987/2777098
  • 不,它在 JFrame 中
  • @ IsabelHM , yeaaaaaaaaahhhhhhhhhhhhhh !!!!!!!!!!!!!!!那行得通....谢谢browwwwww .....

标签: java


【解决方案1】:

如果您想在Windows系统下使用绝对路径,请尝试使用System#getProperty()获取以下目录。

String userHome = System.getProperty("user.home");     
String tempDir  = System.getProperty("java.io.tmpdir"); 

从类所在的同一个包读取

URL url = this.getClass().getResource("water.avi");

从与您项目中的 src 平行的 tmp 文件夹中读取

File file = new File("tmp/water.avi");
URL urlWaterIntake = file.toURI().toURL();

【讨论】:

  • thankssss ... this "URL url = this.getClass().getResource("water.avi");"像英雄一样工作......
猜你喜欢
  • 1970-01-01
  • 2020-09-15
  • 1970-01-01
  • 1970-01-01
  • 2013-10-11
  • 2017-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多