This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21001
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonidas Savvides, please read this.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Notepad.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd need to pay attention to the file encoding.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have any idea how, (or is possible?) in my java scriptlet appended above?
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is correct in my case above, what to close(var?)?

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll answer that question with two questions: Are those the files you have open? Is that how you close files?
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Simply goofing around. Warning: Untested)
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is this last post, is it Java?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem SOLVED used

1.output.flush();
2.convert both text files.lang to UTF-8 fromwithin Notepad++ editor...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic