Results 1 to 5 of 5
  1. #1
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Posts
    24
    Rep Power
    0

    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();
    }
    }

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    12

    Default

    Can you format your code and then to put it between [code] tags [lease, it is hard to read it.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    25

    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. ;)

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,568
    Rep Power
    14

  5. #5
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    11

    Default

    The code written here is not able to understand to viewers.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Storing data from text file in ArrayList
    By tjhodge in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 01:22 PM
  2. Storing and Retrieveing Data Using XStream & xml Files
    By geeeeky.girl in forum New To Java
    Replies: 0
    Last Post: 01-04-2009, 10:24 PM
  3. parsing/storing large text data
    By hkansal in forum New To Java
    Replies: 4
    Last Post: 10-19-2008, 06:34 PM
  4. Storing data permanently
    By shaungoater in forum New To Java
    Replies: 2
    Last Post: 03-10-2008, 04:18 PM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 05:48 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
  •