This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes I want to merge the two files into one of kind: by placing englishKeyword=English  in format Russian Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "I want to merge the two files into one of kind: by placing englishKeyword=English  in format Russian" Watch "I want to merge the two files into one of kind: by placing englishKeyword=English  in format Russian" New topic
Author

I want to merge the two files into one of kind: by placing englishKeyword=English in format Russian

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
I have two text files of exact 3306 lines each of property assigment englishKeyword=English & englishKeyword=Russian
I want to merge the two files into one of kind: by placing englishKeyword=English in format Russian=English (Russian from other file the englishKeyword is exact in sequence and the same...) after print new file... what you suggest? I read Java How to Program 7/e, DEITEL already so I must use Files but how, what technic?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Did you read the entire book?

I'm not sure what you want; you want the "english version" = "the russian version" in a file?

So, you have keys, and properties. Each keyword would have two properties, the English version, and the Russian version. Does this sound like any data structures you're familiar with yet?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18542
    
  40

I read the request as... given...

sSTATUSMENU_CAPTION_ONLINE=Online


and...

sSTATUSMENU_CAPTION_ONLINE=В сети



The resultant file will contain...

В сети=Online


Which can be easily done. Just load the two files into two maps, and iterate through the maps to produce the desired result.

However, there are some issues... First, you are using a "value" from the russian file as the key. Keep in mind that values are not guaranteed to be unique, so your resultant file may not be a valid map anymore. Second, take a look at the result. There is nothing there that says that this field is related to the menu caption. Your program can't say that "this is for that" anymore -- at least, not in a hard coded way.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
Please note that line number is the same contents except one in ru other in english...
Java in unicode of russian characters?
May read the two files line by line same time each, and for each line take the part after "=" and merge it with other file's line to another new file?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure, if it's *guaranteed* to be in the same order. But if that's the direction you're going I'm not sure what the question is. How to read a file? I'm pretty sure that was covered in the book.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
read each two files line by line ... parse line=take only part after =...mearge the strings produced and append to a new file ...all this for each line...
is that correct right...? i know all this to implement!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why not just try it? Get started and see if it works? Write each little piece at a time, make sure it works, then add the next part.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
i AM NOT GOOD IN sTRING FORMATTING, CAN YOU TELL WHEN READ A LINE WITH one =, how get text from first char(including) after =, to end of line?
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Here is a Java tutorial on substring, this should help:
http://download-llnw.oracle.com/javase/tutorial/java/data/manipstrings.html

I couldn't really understand your question, so I hope this is what your were looking for.

Hunter

"If the facts don't fit the theory, get new facts" --Albert Einstein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38041
    
  22
Leonidas Savvides, please read this.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
how do java handle russian characters? Also why the second equal sign and null after each letter? In notepad text appear without in one line wrapped, why? code follows?




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Don't use Notepad.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
how do java handle russian characters=unicode? Also why the second equal sign and null after each letter? I tried NotePad++ but when null appeared nul sign, and russian no seem too...?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You'd need to pay attention to the file encoding.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
you have any idea how, (or is possible?) in my java scriptlet appended above?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
message = ( String ) input.readObject(); // when use this in textField in networking Apps Russian go to client from server without any coding additions, in case of files read/write what must do?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
final I pass problem with UTF-8, that left now is what ever lines (equal always) the ru and eng files have always output file is less in lines eg may 3306 lines produce 3201 lines only OR 106 lines produce 69 lines only rather than equal&complete as espected, where the error???

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I find that code difficult to read.

The only way the loop will stop is if readLine() returns null. It'll write whatever the calculated values are.

Hopefully you close the output file; it's possible that could cause an issue, but it might not.

Are the files the same number of lines?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
yes of course

and type as post 1 shows

first part of left of "=" is identical...

proceed NOT close file to test...?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So take two short example files, put in some logging statements, and figure out where the issue is--it's too difficult to try to read the code and pretend we have the files as well. Print out result, print out when you break out of the loop, print out result3, etc.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
please note that last lines I got in skype7.lang are
3306 lines produce 3201 lines only


106 lines produce 69 lines only


last sentence is finished uncomplete in ru file always...well?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

David Newton wrote:Hopefully you close the output file; it's possible that could cause an issue, but it might not.


In particular, if you don't close a file it's possible you might lose data from the end of the file.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
this is correct in my case above, what to close(var?)?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'll answer that question with two questions: Are those the files you have open? Is that how you close files?
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

(Simply goofing around. Warning: Untested)


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
what is this last post, is it Java?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Linux command line. Tasks like this are most easily and quickly solved using existing tools, like sed, awk, perl, etc. rather than in Java.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
problem SOLVED used

1.output.flush();
2.convert both text files.lang to UTF-8 fromwithin Notepad++ editor...
 
Consider Paul's rocket mass heater.
 
subject: I want to merge the two files into one of kind: by placing englishKeyword=English in format Russian
 
Similar Threads
Merging of log files
Would you prefer English to your native language?
Return of the Soviet Union - Putin Union
Struts 2 properties setting for Date
Jakarta HttpClient : JavaScript in Java