How would I be able to create a new file which will have a different file name each time? Would it also be possible to add line breaks when writing to these files? Also, how would I be able to access this file?
package com.example.create_recipe;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.appcompat.app.AppCompatActivity;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class MainActivity extends AppCompatActivity {
EditText editTxtRecipeName, editTxtEquipment, editTxtIngredients, editTxtMethod, editPersonalStory;
Spinner spnCountries, spnHours, spnMinutes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void createRecipe(Context context) throws FileNotFoundException {
//TODO Create new file - should it be named after the recipe name or a unique int id?
String recipeName = editTxtRecipeName.getText().toString();
String country = spnCountries.getSelectedItem().toString();
String hours = spnHours.getSelectedItem().toString();
String minutes = spnMinutes.getSelectedItem().toString();
String equipment = editTxtEquipment.getText().toString();
String ingredients = editTxtIngredients.getText().toString();
String method = editTxtMethod.getText().toString();
String personalStory = editPersonalStory.getText().toString();
//TODO Write to file, adding new line breaks between recipeName, equipment and so on.
}
}