//为什么我调用系统自带的多媒体播放器可以播放我想要打开的MP3文件,而调用网易云音乐只能打开网易云音乐,但是不会打开我需要打开的MP3文件
package IODemo;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyMp3Demo {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
copyMp3_1();
}
private static void copyMp3_1() throws IOException, InterruptedException {
// TODO Auto-generated method stub
FileInputStream fis = new FileInputStream("惊鸿一面.mp3");
FileOutputStream fos = new FileOutputStream("惊鸿一面之我是SB.mp3");
byte[] buf = new byte[1024];
while ((fis.read(buf)) != -1) {
fos.write(buf);
}
Runtime rt = Runtime.getRuntime();
//调用网易云音乐
// Process p = rt.exec("C:\Program Files (x86)\Netease\CloudMusic\cloudmusic.exe C:\Users\Administrator\Desktop\Java\day13\惊鸿一面.mp3");
//调用系统自带的多媒体播放器
Process p = rt.exec("C:\Program Files (x86)\Windows Media Player\wmplayer.exe C:\Users\Administrator\Desktop\Java\day13\惊鸿一面.mp3");
Thread.sleep(50000);
p.destroy();
fis.close();
fos.close();
}
}
xxx.exe args
的运行方式相当于在程序运行时传递启动参数
比如java 中 public static void main(String[] args) args 就是启动参数
你说的问题,主要看此程序是否支持 通过启动参数来打开文件,手动验证方法:
将需要打开的文件直接拖拽至改程序的启动程序如果能打开 表示该程序支持启动参数打开文件