iterate through map and write the content in a separate file

Ads

 
 

Share on Google+Share on Google+

mahindar
iterate through map and write the content in a separate file
0 Answer(s)      5 years and a month ago
Posted in : Java Beginners

I am trying to save the data from file to a map, then iterate through map and write it to a separate file.My data looks like this:

Concept:Conferences:conferences:confID Concept:Organizations:organizations:orgID Property:conferencesName:namespace:conferences.Name Property:conferencesDate:namespace:conferences.Date

Here are the steps that I did and planning to perform:

  1. I wrote a code that reads through the above file and save it in maps depending on if it
    is a concept or a property.
  2. Next step would be to create a method that write the lines below into a separate file that already exists in computer. map: a d2rq:ClassMap;

    map: a d2rq:PropertyBridge;

  3. The last step would be to iterate through the maps and if it is a concept map write the "key" into the "blank (line 1)" above in step 2 and vice versa for property.

I am new to programming and kind of stuck with steps 2 and 3. Can somebody help me! Please find my code for step 1 here

import java.io.*;
import java.util.*;  

public class ReadAndStoreManual {

public static void main(String[] args)  {
Map<String, List<String>> conceptMap = new HashMap<String, List<String>>();
Map<String, List<String>> PropertyMap = new HashMap<String, List<String>>();
try{
Scanner scanner = new Scanner(new FileReader("C:/"));

while (scanner.hasNextLine()){
String nextLine = scanner.nextLine();
String [] column = nextLine.split(":");
if (column[0].equals ("Concept")){
if (column.length == 4) {
PropertyMap.put(column [1], Arrays.asList(column[2], column[3]));   
    }
else {
conceptMap.put (column [1], Arrays.asList (column[2], column[3]));
    }
}

}
scanner.close();

}

 catch (Exception e) {
 e.printStackTrace();

 }
 System.out.println(conceptMap);
 System.out.println(PropertyMap);

}

}
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
Advertisements
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
Iterate Tag used with a Map.
Iterate Tag used with a Map.  How Iterate Tag used with a Map
Write a program in Java to append content at the end of an already existing file.
Write a program in Java to append content at the end of an already existing file.  Write a program in Java to append content at the end of an already existing file
How to write content of one file to another file.
; In this example we will open a file and then write the content in new file... is : 1836825431 Content of one file successfully written in other file... of the data being written in the second file. About CheckedOutputStream class
How to write content of one file to another file and calculate checksum for accuracy.
on the output stream.  In this Example, we will write the content of a file to another file. And calculate the value of checksum at writing time with the help of CheckedOutputStream class. After it we will read the content of new file
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
Java Map Iterate
Map is an Interface in the Collection Framework. Map is implemented by its two sub classes HashMap Treemap Map has no iterator method. So use the entrySet() method.It returns the data as Set Example of Java Map
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those... with idea of saving those values in a separate file and updating values in file... can i write and update value in that file
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java... will be able to use OutputStreamWriter on a FileOutputStream classes to write data to a file from Java program. To write the Java Write To File we will use two
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks
Write data in doc file
Write data in doc file  How to write data or string in word file
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How to write in File of Java Program
Java write to file
Java write to file  How to write to a file in Java? Is there any... files. You can easily use the the FileWriter and BufferedWriter to write data to a text file. Here is the examples: Example program to write to file. File
run a batch file through javascript
run a batch file through javascript   How to run a batch file through javascript without prompting
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
How to Write to file in Java?
How to Write to file in Java?  How to Write to file in Java Program... the Examples of How to write to File in Java Program: WriteToFileExample.java import... how to write in a file."); br.close(); } catch (Exception e) { System.err.println
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
Writing and reading from/to a serialized file through Hash Table in Java
illustrates you how to read and write from/to a serialized file through the hash table... Writing and reading from/to a serialized file through Hash Table in Java... the the program creates the serialized file otherwise. This program first write
How to Write to a File in Java without overwriting
overwriting the content of "log.txt" file. Next time if you write... in a text file through your Java program. Program explained here writes the content...Learn how to Write to a File in Java without overwriting in your Java program
changing the file content
, reading the file content and changeing the 501 line content and crating one... in 501 line but it take lot of time to read all content of old file and storing in new file. Please help me ,Is there any better logic to chang content
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file in Java   Hi, To create Comma separated value(CSV) file is very simple... passed the file name to write into a stream characters. Then we use the FileWriter
how to write file from FileInputStream
how to write file from FileInputStream  Hi, How to Write a file.... Thanks,   Hi, For Write to file from FileInputStream in java you may use... this website Write to file from FileInputStream in java
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use
how to write to file at the end of the line
how to write to file at the end of the line  Hi, Where do i learn how to write to file at the end of the line using Java program. Plz suggest... will help you for "How to write the file at the end of line using Java language
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2...); oos.writeObject("Ankit"); oos.writeObject("Content Writer
write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )
write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )  write aprogram which shows the use of hashset and iterator (through enter the value through keyboard