Results 1 to 3 of 3
  1. #1
    Rock-On is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default Readin from a file. and storing the information. (read inside)

    Java Code:
    	public void encryptFile(String fileName) {
    		try { 
    			String inputFile = fileName+".java";
    			File file = new File(inputFile); 
    			int fileLength = (int)file.length(); 
    			byte fileBytes[] = new byte[fileLength]; 
    			DataInputStream dos = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile))); 
    			dos.readFully(fileBytes, 0, fileLength); 
    			File Name = new File(inputFile);
    			for(int currentByte = 0; currentByte < fileBytes.length; currentByte++)
    				fileBytes[currentByte] = (byte)(~fileBytes[currentByte]);
    			FileOutputStream encryptedFile = new FileOutputStream(fileName+".txt");
    		} catch(Exception ex) { ex.printStackTrace(); }
    Hello. I am using the above code (^^) to encrypt my .java files to .txt files and delete the .java ones, so they go from example:

    Java Code:
    import javax.swing.JFrame;
    public class File1 {
    	static JFrame frame = new JFrame();

    Java Code:
    (i actually encrypted it.)

    now i ned to be able to read from this by doing something like

    (this wont work)
    Java Code:
    [add unencryptin code here.]
    File Frame = new File(File1);
    so i can now do.

    Java Code:
    and thus letting me read my files with out storing it in .java so my code cannot be leeched or something.

    thank-you for your help.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Your encryption code is a (very weak) two way encryption because all you do is flip every bit in the data. Apply the same code again to the encrypted data and voila, you'll have your original data back.

    kind regards,


  3. #3
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Rep Power


    why would you encrypt java files?
    normally you only distrebute a class file whitch is already encrypted?

Similar Threads

  1. storing information
    By bsebal28 in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 08:10 AM
  2. Problem with storing an image into file???
    By pavankumar.thati in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-22-2009, 04:35 PM
  3. Storing the data in a file
    By vasavi.singh in forum New To Java
    Replies: 4
    Last Post: 02-20-2009, 04:01 PM
  4. Help in storing Information
    By care in forum New To Java
    Replies: 1
    Last Post: 12-01-2008, 09:16 PM
  5. storing and retrieving a file as such
    By anil_manu in forum Advanced Java
    Replies: 0
    Last Post: 03-11-2008, 01:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts