In my android application i would like to replace my first line of a txt file with some other data.
Is there any way that i can do this.
Please let me know your valuable suggestions.
Thanks in advance 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Due to the nature of Java IO and the disk file system, it is not directly possible to replace an arbitrary “line” of a file without taking the remnant of the file into consideration. You need to fully read and write the file.
The
BufferedReaderandPrintWriterare helpful in this. The former offers areadLine()method and the latter offers aprintln()method (which compensates the fact that thereadLine()eats the newline). Add somebooleanwhich you can use in the loop to determine if the first line has to be processed or not.