Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-20-2009, 08:29 AM
Member
 
Join Date: Feb 2009
Posts: 24
Rep Power: 0
vasavi.singh is on a distinguished road
Default Storing the data in a file
I am attaching the code also.

AddingNewArticleIntoNetwork.java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AddingNewArticleIntoNetwork
{
private static final BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
public static String articleId;
public static int citations,year,noOfAuthors;
public static String authorName[]=new String[20];
public static int publications[]=new int[20];

public static int readInput()
{
System.out.println("Enter the article title: ");
articleId=readString();
System.out.println("Enter the citations of the article: ");
citations=readInt();
System.out.println("Enter the year of publications: ");
year=readInt();
System.out.println("Enter the number of Authors: ");
noOfAuthors=readInt();
System.out.println("Enter the author name and the publications: ");
for(int i=0;i<noOfAuthors;i++)
{
authorName[i]=readString();
publications[i]=readInt();
}
return noOfAuthors;
}
public static int readInt( )
{
String inputString = getInput( );
return Integer.parseInt(inputString);
}
public static double readDouble( )
{
String inputString = getInput( );
return Double.parseDouble( inputString );
}
public static String readString( )
{
String inputString = getInput( );
return inputString;
}
private static String getInput( )
{
String inputString = null;
try
{
inputString = keyboard.readLine( );
}
catch ( IOException e )
{
e.printStackTrace( );
}
return inputString;
}
}

Main.java

import jsns.model.CommunicationNetworkId;
import jsns.model.util.ContinuousTime;
import jsns.model.util.LoggingMasterImpl;
import jsns.model.IEnvironment;
import jsns.model.util.EnvironmentImpl;
import jsns.system.SimulationControl;
import java.lang.String;
import java.io.*;

public class Main
{
static int authorCount,newArticleCitations,newArticleYear;
static String newArticleId,newArticleAuthorNames[]=new String[20];
static int newArticleAuthorsPublications[]=new int[20];
PrintWriter pw=null;

public static void main(String args[])
{
Main mainObj=new Main();

AddingNewArticleIntoNetwork newArticleInfo=new AddingNewArticleIntoNetwork();
authorCount=newArticleInfo.readInput();
newArticleId=newArticleInfo.articleId;
newArticleCitations=newArticleInfo.citations;
newArticleYear=newArticleInfo.year;

System.out.println("Article Id: "+newArticleId);
System.out.println("Citation count: "+newArticleCitations);
System.out.println("Year of publishing: "+newArticleYear);
System.out.println("List of authors names");
for(int i=0;i<authorCount;i++)
{
newArticleAuthorNames[i]=newArticleInfo.authorName[i];
System.out.println(newArticleInfo.authorName[i]);
newArticleAuthorsPublications[i]=newArticleInfo.publications[i];
System.out.println(newArticleAuthorsPublications[i]);
}
mainObj.writeDataIntoAFile();
}
public void writeDataIntoAFile()
{
try
{
FileOutputStream raf = new FileOutputStream("PrintOutput.txt");
pw=new PrintWriter(raf, true);
pw.print(newArticleId+" "+newArticleCitations+" "+newArticleYear+" ");
/* DataOutputStream dos = new DataOutputStream(fos);
dos.writeChars(newArticleId);
dos.writeInt(newArticleCitations);
dos.writeInt(newArticleYear);
dos.writeInt(authorCount);
*/ for(int i=0;i<authorCount;i++)
{
/*dos.writeChars(newArticleAuthorNames[i]);
dos.writeInt(newArticleAuthorsPublications[i]);*/
pw.print(newArticleAuthorNames[i]+" "+newArticleAuthorsPublications[i]);
}
mainObj.storeTheData();
}catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
finally
{
if(pw!=null)
pw.close();
}
}
public void storeTheData()
{
String inLine;
BufferedReader br=null;
try
{
br=new BufferedReader(new FileReader(raf))
inLine=br.readLine();
}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-20-2009, 08:48 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 484
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
Can you format your code and then to put it between [code] tags [lease, it is hard to read it.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-20-2009, 09:34 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,481
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
And also, if you get any errors please send it here to see. You must explain your question more clearly. I don't think anyone wants to run your code and see what happen for you.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-20-2009, 09:50 AM
Senior Member
 
Join Date: Jun 2008
Posts: 1,385
Rep Power: 3
masijade is on a distinguished road
Default
Seemingly a continuation of Writing the data into RandomAccessFile
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-20-2009, 05:01 PM
makpandian's Avatar
Senior Member
 
Join Date: Dec 2008
Location: Chennai
Posts: 253
Rep Power: 2
makpandian is on a distinguished road
Default
The code written here is not able to understand to viewers.
__________________
Mak
(Living @ Virtual World)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing data from text file in ArrayList tjhodge New To Java 1 02-12-2009 02:22 PM
Storing and Retrieveing Data Using XStream & xml Files geeeeky.girl New To Java 0 01-04-2009 11:24 PM
parsing/storing large text data hkansal New To Java 4 10-19-2008 07:34 PM
Storing data permanently shaungoater New To Java 2 03-10-2008 05:18 PM
Storing Data Khorod New To Java 1 08-03-2007 06:48 AM


All times are GMT +2. The time now is 01:48 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org