Results 1 to 2 of 2
  1. #1
    tzulu is offline Member
    Join Date
    Jul 2011
    Rep Power

    Default Need help! Encoding from a file.

    Been working on this for a while now..

    The idea is to "encode" a text file, then pass it on to the console and also a new file. Such as taking input from a text file that reads "Hello" and convert it for output reading "ifmmp". Each character value gets 1 added to it. Also each line of input should transfer to a "coded" line of output, then go to the next line.

    The closest I can get to it is either just displaying the first line or if I change it to 'println' it displays everything, but as single characters per line.

    Any help would be much appreciated!

    Java Code:
            char sNew;
            String sOld = fin.readLine();
            while ((sOld = fin.readLine()) != null)
              for (int i = 0; i < sOld.length(); i++)
                     if (i < sOld.length())
                     sNew = (char)(sOld.charAt(i) + 1);
              } //for
            } //while

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


    Have a look at the StringBuilder class; it can collect your sNew characters and convert the entire char sequence to a String at the end.

    kind regards,

    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Change XML file encoding
    By karq in forum XML
    Replies: 0
    Last Post: 06-16-2011, 10:29 AM
  2. Encoding Problems in JRE
    By xlomo in forum New To Java
    Replies: 3
    Last Post: 02-28-2011, 10:13 AM
  3. Replies: 0
    Last Post: 07-20-2010, 12:56 PM
  4. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 12:22 AM
  5. How to convert the encoding of a file
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 03:48 AM

Posting Permissions

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