问题描述
我是新来的Android开发方面,我需要帮助。我有两个问题分别是:
I'm new to android developing, and I'm in need of help. I've got two problems which are:
- 我不知道如何创建我的主目录中两个子目录。我知道里面怎么一个目录下创建子目录(
文件目录=新的文件(Environment.getExternalStorageDirectory()+的Saling-威卡/音频和放大器;文本文件);
),但我确实想在那里将是我的主要子目录里面的两个子目录。(音频文件和放大器;文本文件中的Saling,威卡目录这是主要的目录内不同的两个子目录) -
我不知道我怎么我会能够到我的数据保存到我创建子目录。
这里是我的记录模块,其中音频数据是从哪里来的code:
- I don't know how to create two subdirectories inside my main directory. I know how to create subdirectory inside of a directory (
File directory = new File(Environment.getExternalStorageDirectory()+"Saling-Wika/Audio&Text Files");
), but what I do want is there would be two subdirectories inside of my main subdirectory (The Audio Files & Text Files are different two subdirectories inside the Saling-Wika directory which is the main directory). I don't know how I'm gonna be able to save my data into the subdirectories I've created.Here is the code of my record module where the audio data is coming from:
public class RecordModule extends Activity {
Button SpeakBtn, StopBtn;
private MediaRecorder myAudioRecorder;
private String outputFile = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recordmodule);
SpeakBtn = (Button) findViewById(R.id.SpeakBtn);
StopBtn = (Button) findViewById(R.id.StopBtn);
StopBtn.setEnabled(false);
SpeakBtn.setEnabled(true);
SimpleDateFormat datetime = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = datetime.format(new Date());
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + format + ".3gp";
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
SpeakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
}
catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SpeakBtn.setEnabled(false);
StopBtn.setEnabled(true);
Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_SHORT).show();
}
});
StopBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder = null;
StopBtn.setEnabled(false);
SpeakBtn.setEnabled(true);
Toast.makeText(getApplicationContext(), "Audio recorded successfully", Toast.LENGTH_SHORT).show();
}
});
}
我想我的音频数据将被存储到音频文件目录,但我不知道我是如何会是能够做到这一点。请帮我。
I want my audio data will be stored into the Audio Files directory, but I don't know how I'm gonna be able to do that. Please help me.
推荐答案
我终于解决了我的问题,这里是我所做的解决方案:
I've finally solved my problems, and here are the solutions I've done:
String folder_main = "Saling-Wika"
File MainDir = new File (Environment.getExternalStorage();, folder_main);
if (!MainDir.exists()){
MainDir.mkdirs();
}
File f1 = new File (Environment.getExternalStorage() + "/" + folder_main, "Audio Files");
if (!MainDir.exists()){
MainDir.mkdirs();
}
File f2 = new File (Environment.getExternalStorage() + "/" + folder_main, "Text Files");
if (!MainDir.exists()){
MainDir.mkdirs();
}
}
下面是code,我如何创建两个子目录(音频和放大器;文本文件的文件夹)的主目录(萨零-威卡fodler)
Here is the code how I've created two subdirectories (Audio & Text Files folders) inside of the main directory (Saling-Wika fodler).
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Saling-Wika/Audio Files/" + format + ".3gp";
这是我的音频文件是如何被保存到音频文件的文件夹。
And here is how my audio files are being saved into the Audio Files folder.
这篇关于一个目录中创建的子目录,并能够将数据保存到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!