Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Hi Everybody, I am having a problem with writing data from a text file using RandomAccessFile stream. The problem is this; If the password is greater than the existing password then the next line characters(beginning) are being chopped off. Is there anything wrong in the code that i have written;The code is as follows: Any help on this is highly appreciated, import java.io.RandomAccessFile; public class TPassfileManagerBatchUnix implements IPassfileManagerBatch{ /* * @param strPasswordFile the file name to be update the password. public String updateAppendPassword(String strPasswordFile, boolean fCaseSensitive , String strUserName, String strPassword) throws IOException { /** e.g line in the password file. //*********** File System Object Checking **************** // check whether the given file exists in the file system // check the file is readable // check the file for writable // opens the file for read and write mode try{ //each line in the password file. long lStartPos; // starting position of the line. // read the file until EOF reaches strLine = strLine.trim(); //Check if the line is blank // split the line with the delimeter ":" and store each value in the // check the current line is for the User. //Update the Password with the New Password. // prepare the new line with the new password.
// Check if the new line lenght is lessthan the old Line if( strNewLine.toString().length() < strLine.length()){ iLengthDiff = strLine.length() - strNewLine.toString().length(); for (int i=0; i /* * the new line lenght is lessthan the existing line /* * if the NewLine length is greater than the OldLine // move the pointer to the starting postion of the line. // find the lenght of the file size. //increase the file size to number of extra characters in the new password // write the new line into the file. //close the file stream // return SUCCESS and exit from the function. } // if the password matches }// if the line is empty // get the next line strating postion before reading the next line. }// while loop until the EOF /* * if the password is not found until the End of File strAppendLine = strUserName + COLON + strPassword; raf.writeBytes( "\n" + strAppendLine ); raf.close(); }// try block catch(FileNotFoundException Ex){ catch(Exception e){ }//function // This method splits the given String with the ":" delimeter. Jyothi
|
Sponsored Links
|