Read write file in specific manner - java

I have read and write file in a specific manner.
Format of file:
a1(1,2,5,8,0);
a2(4,6,8,4);
a7(4,5,7,8);
At a time if I modify section for a2 say like "2,4,6,8", how should I modify the file.
And how can I read values for specific title. That is, if I want to fetch values only for a7, then the method should return 4,5,7,8.
Thank You

"how should I modify the file"
To modify the content of the file, you need to write it into the temporary file. After you finish, delete the original and rename the temporary file as the original file name.
"how can I read values for specific title"
Read the file line by line and search for your specific title:
if(line.contains("a7")){
System.out.println(line.substring(line.indexOf("("),line.indexOf(")")+1));
}

Related

How to write to one file from another at specific line?

I want to copy all of content from one file to another existing file, to a specific line.
File 1, File 2, Expected result
I used FileWriter to write both files, now I don't know how to merge them like this. I know how to write from one to another file but only to append one files content to the end of another file. But I need it to copy one file's content to another but at specific line, like in example pics. In example if you look, content is copied between two brackets of class ({}). Any ideas?

Java - Replace specific line in file without copying all data to another file

I have some text file named data.dat. The second line contains a number which I would like to update to another number. The file can get pretty huge so I don't want to create any temporary files and copy over all this data to another file just to change a single line. Is there a way?

Read multiple .txt files and write information to an Array

I have a method that creates files containing the name and age and writes, Example "name.txt" and the content is .. name-age .. would like to get this information from 10 .txt files and write in a single file, line after line
You can iterate through files inside a directory. In each file you can iterate through lines and print them out.

About quickfix .seqnums file

I want to read the value in quickfixj .seqnums file and write that value in another file or overwrite existing value with another value using java.i am beginner in java tell me how i can do this my boss give me the task.help me
We're not going do your job for you, but here is a set of steps:
Open the file (it's a text file - if you'd bothered to cat the file you would have seen)
There are two numbers - figure out which is which
Update as required
Write the new values in the same format to the file.

How to append existing line within a java text file

I'm having trouble adding to an exsisting line in a text file without overwriting that particular line or adding a new line.
for example, i have a line in my text file which is:
hello my name is
I would like to add to this line so it becomes:
hello my name is joe bloggs
Thanks
i have a task to create a help desk program and i am trying to incorporate a feature that enables users to edit questions they have posted. as a result, the program will need to be able to append Any line within the text file - not necessarily just the last line
If it's not at the end of the file, you're in trouble - you're basically talking about inserting data in the middle of a file, which isn't traditionally supported by file systems.
The normal way to approach this is to create a new file - copy the portion before the insertion point from the old file, then write your new data, then copy the remainder of the original file afterwards. Finally, do whatever renaming/deleting you need.

Categories