FileInputStream in Fragment giving FileNotFound exception

I'm attempting to save integers on internal storage using a fragment class, and seem to be able to use FileOutputStream to save files, but the program never seems to be able to find them once created.

Here's the relevant Java class:

public View onCreateView(final LayoutInflater inflater, final ViewGroup container,

final Bundle savedInstanceState) {

View root = inflater.inflate(R.layout.fragment_preferences, container, false);

final SeekBar s1 = (SeekBar) root.findViewById(;

Button button = (Button) root.findViewById(;

button.setOnClickListener(new View.OnClickListener() {


public void onClick(View v) {

int spi = s1.getProgress();

String fileContents = String.valueOf(spi);

try {

FileOutputStream outputStream = getActivity().openFileOutput("myText.txt", Context.MODE_PRIVATE);



Toast.makeText(getContext(), "File saved!", Toast.LENGTH_SHORT).show();}

catch (Exception e){


Toast.makeText(getContext(), "File not saved!",...

Read More »

By: StackOverFlow - Thursday, 20 September

Related Posts