Can anyone help me how to change a line in a file using java IO function. The file is located at SDCard. I have tried some solution from different blog, but failed.
I need to change one attribute wpa_oper_channel=1
to 2,3,4.....
as user demand in the file sdcard/sample.txt
.
I have also tried using SED
command, but still not working. Please suggest if there any solution using java IO function.
The Command I have used using SED
:
sed -i 's/wpa_oper_channel=[0-9]\\+/wpa_oper_channel=7/' sample.txt
If your configuration file is in the form of a Properties file. This means each line is in a format of
key=value
. You can easily read, modify and write it. Here is an example, I assume you have no problem with reading and writing a file through streams.By doing this, you may lose if there is another type of line like comments or else.
Update
I updated to source code. But still you need to get read and write permission.
I haven't test the code, It will work with some exception handling. If it is not work please specify your error.