我正在尝试创建MP3播放器程序,并且需要一种将mp3的文件路径存储在变量中的方法,以便可以将变量加载到另一个类中并播放该文件。现在,用于保存/加载的当前代码块是.txt,但是我需要将其替换为变量save。
try {
// What to do with the file.
textarea.read( new FileReader( file.getAbsolutePath() ), null );
} catch (IOException ex) {
System.out.println("Problem accessing file"+file.getAbsolutePath());
}
} else {
System.out.println("File access cancelled.");
}
我在类中使用这些导入来读取变量,
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.net.*;
import java.io.*;
import java.io.FileInputStream;
import java.util.*;
import javazoom.jl.player.*;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ResourceLoader;
以及有关课程的导入。
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try{
FileInputStream mp3 = new FileInputStream(fileChooser.getSelectedFile());
Player playMP3 = new Player(mp3);
}catch(Exception e){System.out.println(e);
} }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句