File I/O not working :(

All your problems with Audio, Video and Images.

File I/O not working :(

Postby philociph3r » Sun Jul 10, 2011 2:05 am

the following algorithms should encrypt (or in the event of a logic error in the actual algorithm AT LEAST corrupt) a picture. However, although it compiles fine, the app doesn't have any effect on the files. I have already been through it with the debugger to ensure that the function receives the correct arguments.

Code: Select all
public void encryptpic(String key, File pic) throws FileNotFoundException {

      int check1 = pic.hashCode();
      String path = pic.getName();
   
      FileInputStream infile = openFileInput(path);
      FileOutputStream outfile = openFileOutput(path,
            Context.MODE_WORLD_WRITEABLE);


   

       long count = 0;
         count = pic.length();
      
       int iteration = 0;


       int read = 0;
       
       while (iteration < count) {
       try {
         read = infile.read();
      } catch (IOException e1) {
         alert("failed to read");
         e1.printStackTrace();
      }
   
          try {
             
            outfile.write(read ^ key.hashCode());
         } catch (IOException e) {
            alert("failed to write!");
            e.printStackTrace();
         }
          iteration++;
      }
       int check2 = outfile.hashCode();
       if (check1 == check2) {
          alert("suicide"); }
      
       try {
         outfile.flush();
         outfile.close();
      } catch (IOException e) {
         alert("failed flush");
         e.printStackTrace();
      }
       try {
         infile.close();
      } catch (IOException e) {
         alert("close failed");
         e.printStackTrace();
      }

} //end encrypt()
philociph3r
Freshman
Freshman
 
Posts: 2
Joined: Sun Jul 10, 2011 1:53 am

Top

Re: File I/O not working :(

Postby philociph3r » Tue Jul 19, 2011 9:22 pm

Bump :'(
philociph3r
Freshman
Freshman
 
Posts: 2
Joined: Sun Jul 10, 2011 1:53 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 23 guests