我对 java 非常陌生,并试图扩展 File 类以使用下面的类向它添加更多方法和属性
import java.io.File;
public class RecordingFile extends File {
private static final long serialVersionUID = -4774703382591639948L;
String RecordingNameFormatted;
String RecordingDurationFormatted;
String RecordingSizeFormatted;
String RecordingDateFormatted;
String RecordingBitrateFormatted;
public RecordingFile(String path) {
super(path);
File f = new File(path);
RecordingNameFormatted = f.getName().replace(".mp3", "");
RecordingDurationFormatted = Utils.millisecondsToHours(Utils.getMp3DurationPureJava(f));
RecordingSizeFormatted = Utils.humanReadableByteCount(f.length(), true);
RecordingDateFormatted = Utils.longToDate(f.lastModified());
RecordingBitrateFormatted = Utils.getBitratePureJava(f) +"Kbps";
}
}
以上不能正常工作。我什至不确定是否
File f = new File(path);
应该在那里。例如,当我尝试这个
ArrayList<RecordingFile> ret = new ArrayList<RecordingFile>();
RecordingFile filesDir = new RecordingFile(path);
if (!filesDir.exists()) {
filesDir.mkdirs();
}
RecordingFile[] list = filesDir.listFiles();
Eclipse 告诉我“类型不匹配:无法从 File[] 转换为 RecordingFile[]”我如何才能通过添加更多属性/方法来扩展 File 类?