Jump to content

file exist error

Recommended Posts

hello all!

i'm new to java and android studio.

i was trying to check and create new file and do something in it.

                    if (!file1.exists()) {
                        try {
                            Toast.makeText(StartActivity.this, "key file created!" + directory, Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(StartActivity.this, KeyActivity.class);
                        } catch (IOException e) {
                            Toast.makeText(StartActivity.this, "key file creation failed!" + directory + "--" + e, Toast.LENGTH_LONG).show();
                    } else {
                        StringBuilder keyData = new StringBuilder("");
                        try {
                            FileInputStream kfile = openFileInput(keyfile);
                            InputStreamReader kSr = new InputStreamReader(kfile);
                            BufferedReader bufferedReader1 = new BufferedReader((kSr));
                            String readKey = bufferedReader1.readLine();
                            if (readKey != null) {
                                final String key = keyData.toString();
                                Toast.makeText(StartActivity.this, "found login id and key on " + directory + "! Checking the credentials!", Toast.LENGTH_LONG).show();
                                new AsyncLogin1().execute(loginId, key);
                            } else {
                                Intent intent = new Intent(StartActivity.this, KeyActivity.class);
                                intent.putExtra("loginID", loginId);
                        } catch (IOException ioe1) {
                            Toast.makeText(StartActivity.this, "error: " + ioe1, Toast.LENGTH_LONG).show();  // this is the part that is displayed as error

i tried all these and got unexpected error!

while running this, it goes inside the file existence block and returns the IOException error saying "No such file or directory". Please someone guide me where i made mistake.


this is the file path:

File thisdirectory = this.getFilesDir();
File directory = new File(thisdirectory + "/online/is_cool_staffs/");
if (!directory.exists()) {
File file1 = new File(directory + keyfile);


thank you in advance...

Edited by funbinod
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...