1、我把1.mp3的音频文件上传到服务器,代码如下
@Override
public void addGoods(Map params) throws Exception {
dao.addGoods(params);
if (params.containsKey("photo"))
MyUtils.fileAdd("hn_goods" + File.separatorChar + params.get("go_id").toString(), params.get("photo").toString());
}
这里都是没有问题的
2.public static void fileAdd(String path,String file) throws IOException {
if (file != null && file.length() > 0) {
String[] photos = file.split(",");
String basePath = uploadPath + path + File.separatorChar;
File baseFile = new File(basePath);
if (!baseFile.exists())baseFile.mkdirs();
String sourcePath = uploadPath + "temp" + File.separatorChar;
for (String p:photos) {
File sourceFile = new File(sourcePath + p);
FileChannel srcChannel = new FileInputStream(sourceFile).getChannel();
FileChannel dstChannel = new FileOutputStream(basePath + p).getChannel();
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
srcChannel.close();
dstChannel.close();
sourceFile.delete();
}
}
封装的路径什么的都在这里
3、哪位大神可以告诉我,我要取项目中服务器上的1.mp3音频文件的时长怎么取路径??
File file = new File("。。。。。。。。。。。。????");
try {
MP3File f = (MP3File)AudioFileIO.read(file);
MP3AudioHeader audioHeader = (MP3AudioHeader)f.getAudioHeader();
System.out.println(audioHeader.getTrackLength());
} catch(Exception e) {
e.printStackTrace();
}