-
Comparing text files
Hi,
I have a somewhat abstract question, in that i dont have any code examples for what i am trying to do. Basically i want to write some code that will take a number of files, and compare them, picking out words that appear frequently in all the files. Now im relatively new to java and still trying to get my head around it, so what im looking for is a few pointers how to get started on this. Does anybody have any suggestions?
Thanks
-
hi,
You can take a look at this Thread.
http://forum.java.sun.com/thread.jspa?threadID=673881
Sincerely,
Tien-Chih Wang
-
Thanks that seems to be exactly what im looking for. How would i write a simple main method to test that? For clarity, that being this code:
private static final String DELIM = ",";
/**
* Compile two files.
*
* @param file1 String the input file 1
* @param file2 String the input file 2
* @param file3 String the output file
* @throws IOException error in reading/writing
*/
public void compileFiles(String file1, String file2, String file3) throws
IOException {
BufferedReader reader1 = new BufferedReader(new InputStreamReader(
new FileInputStream(file1)));
BufferedReader reader2 = new BufferedReader(new InputStreamReader(
new FileInputStream(file2)));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file3)));
String line1 = reader1.readLine();
String line2 = reader2.readLine();
while (line1 != null && line2 != null) {
writer.write(compileLines(line1, line2));
writer.newLine();
line1 = reader1.readLine();
line2 = reader2.readLine();
}
reader1.close();
reader2.close();
writer.close();
}
private String compileLines(String line1, String line2) {
StringTokenizer tok1 = new StringTokenizer(line1, DELIM);
StringTokenizer tok2 = new StringTokenizer(line2, DELIM);
String name = tok1.nextToken();
String number = tok1.nextToken();
String scheme = tok1.nextToken();
// ignore number
tok2.nextToken();
String date = tok2.nextToken();
String value = tok2.nextToken();
StringBuffer buffer = new StringBuffer();
buffer.append(name);
buffer.append(DELIM);
buffer.append(number);
buffer.append(DELIM);
buffer.append(date);
buffer.append(DELIM);
buffer.append(scheme);
buffer.append(DELIM);
buffer.append(value);
return buffer.toString();
}
Thanks again
-
>How would i write a simple main method to test that?
What is the "that" you want to test?
What is the purpose of the code you posted? It looks like its merging fields from two files into a third file.
-
I have C# one , it may help you , C# Syntax is almost like Java :
See the code here : http://www.smartvi.com/webservices.htm
Regards
Similar Threads
-
By Hutty in forum ASP.NET
Replies: 0
Last Post: 09-27-2005, 04:11 PM
-
Replies: 2
Last Post: 02-28-2002, 10:53 AM
-
Replies: 3
Last Post: 08-30-2001, 11:45 AM
-
By George Gilbert in forum vb.announcements
Replies: 0
Last Post: 08-19-2001, 11:34 AM
-
By Larry Rebich in forum VB Classic
Replies: 1
Last Post: 12-15-2000, 10:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks