繁体   English   中英

将MP3文件路径存储到变量并从另一个类读取的简单方法?

[英]Easy way to store MP3 file-path to variable and read from another class?

我正在尝试创建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);

} }   
}  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM