About quickfix .seqnums file - java

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.

Related

How to read/print the contents for excel file using docx4j?

I've been googling and I've not found one example for this.
I am able to extract the contents for a DOCX file but so far no clue how to get the contents of an EXCEL file.
I know you use
SpreadsheetMLPackage spreadsheetMLPackage = SpreadsheetMLPackage.load(file);
to load the file, but I don't know how to proceed from here. I've check whatever methods SpreadsheetMLPackage has but nothing has gotten me the contents.
First you need to understand the structure of a xlsx file.
Unzip one, or run it through the docx4j webapp.
For how the parts relate to one another, see:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2007/08/13/1970.aspx
I guess the key method you'll want is getWorksheet
But first you'll need to get the WorkbookPart; do that with spreadsheetMLPackage.getWorkbookPart()

How do I read this particular *.DAT file? (From Age of Empires 2)

Basic info: I have a DAT file from Age of Empires 2 Conquerer, the expansion pack (Forgotten Empires).
Question: I want to be able to read the contents of it. I tried using FileReader method and FileInputStream - ObjectInputStream. The first one gives me a weird output "ì½|÷óÿ—..." and the other one gives me this error: java.io.StreamCorruptedException: invalid stream header: ECBD057C
Afaik, every DAT file is different and one needs to know how it was made.
I am noob at programming, so please excuse me if I haven't provided enough info.
More Details: Link to the file - http://www.4shared.com/file/6SkPpm6r/empires2_x1_p1.html
There are tools to read this file and edit it, however, I want to read it in a simple java program and extract what's inside of it. Tool to read it: http://aok.heavengames.com/blacksmith/showfile.php?fileid=11002
Thanks a lot!
If you want to read it online, go to NBT Editor. Drop the file there (from your File Explorer). The File may be in a readable format.

How to read from a dynamic excel file?

Values in my dynamic excel file are changing every second, and i would like to read the new values through java. The problem I am facing is that I have to always save the file and then load its values to the program. Is it possible that excel internally saves the file automatically so that I'm loaded with new values every time.
Aman, can you clarify from where your excel sheet being updated dynamically? if you are writing it via another program, then you must use write method in the output stream. then only the values will be persisted
Values in my dynamic excel file are changing every second
Does this means it is saved in hard drive already or to be saved?
Who is changing the value? You or other application?
Make sure the changes are persisted. Other wise you are reading the same value from HD, not from RAM.
Is it possible that excel internally saves the file automatically
For this you need to use VBA., which I don't think you need to know.
But you can do that yourself from Java.
You keep this excel file in a folder and start a thread that will monitor the excel file. Means you can poll this excel file and get the latest content in your java code.

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.

In java, how do i edit 1 line of a text file?

Ok so I know the value of the line, I dont have the line number, how would I edit only 1 line?
Its a config file, i.e
x=y
I want a command to edit x=y to x=y,z.
or even x=z.
In Java you can use `Properties class:
app.config file:
x=y
java:
public void writeConfig() throws Exception {
Properties tempProp = new Properties();
tempProp.load(new FileInputStream("app.config"));
tempProp.setProperty("x", "y,z");
tempProp.store(new FileOutputStream("app.config"), null);
}
If you are using that configuration format, you might want to use
java.util.Properties
component to read/write on that file.
But if you just want to edit it by hand, you can just read the file line by line and match the variable you want to change.
One way to do it is to:
Read the file into memory; e.g. as an array of Strings representing the lines of the file.
Locate the String/line you want to change.
Use a regex (or whatever) to modify the String/line
Write a new version of the file from the in memory version.
There are many variations on this. You also need to take care when you write the new version of the file to guard against losing everything if something goes wrong during the write. (Typically you write the new version to a temporary file, rename the old version out of the way (e.g. as a backup) and rename the new version in place of the old one.)
Unfortunately, there is no way to add or remove characters in the middle of a regular text file without rewriting a large part of the file. This "problem" is not specific to Java. It is fundamental to the way that text files are modelled / represented on most mainstream operating systems.
Unless the new line has the exact same length as the old one, your best bet is to
Open a temporary output file
Read the config file, line by line
Search for your key
If you can't find it, just write the line you just read to the output file
If you can find it, write the new value to the temporary file instead
Until you hit EOF
Delete old file
Rename new file to the old file
IF your config file is small, you can also do the whole parsing/modification step in memory and then write the final result back to the config file, that way you skip the temporary file (although a temporary file is a good way to prevent corruption if something breaks while you write the file).
If this is not what you're looking for, you should edit your question to be a lot more clear. I'm just guessing what you're asking for.
If your data is all key and value pairs, for example ...
key1=value1
key2=value2
... then load them into a Properties object. Off the top of my head, you'll need a FileInputStream to load the properties, modify with myProperties.put(key, value) and then save the properties with the use of a FileOutputStream.
Hope this helps!
rh

Categories