Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 48

Thread: Difficulty in creating/writing to a file (also, with reading file with data)

  1. #1
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Difficulty in creating/writing to a file (also, with reading file with data)

    Hi guys.
     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package daos;
     
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import model.City;
    import model.YearData;
     
    import repositories.Repository;
     
    /**
     *
     * @author mga
     */
    public class DAOTextImpl implements DAOInterface {
          private ArrayList<YearData>yeardata;
     
        static final char DELIMITER=',';   
     
     
     
     
        @Override
        public Repository load(String filename) {
     
            Repository repository = new Repository();
     
            try (BufferedReader br = new BufferedReader(new FileReader(filename))) { 
                String[] temp;
                String line = br.readLine();
                while(line!=null){
                    temp=line.split(Character.toString(DELIMITER));        
                    int id = Integer.parseInt(temp[0]);
                    String cityName = stripQuotes(temp[1]);
                    String country=stripQuotes(temp[2]);
                    City city=new City (id, cityName, country);
     
     
     
     
                      /*  line=br.readLine();
                        temp=line.split(Character.toString(DELIMITER));
                        String year=stripQuotes(temp[4]);
                        float precipitation=Float.parseFloat(temp[5]);
                        int maxTemp=Integer.parseInt(temp[6]);
                        int minTemp=Integer.parseInt(temp[7]);
                        int windSpeed=Integer.parseInt(temp[8]);
                        String windDirection=stripQuotes(temp[9]);
                     YearData yeardata=new YearData(year, precipitation, maxTemp, minTemp,windSpeed, windDirection); */
     
                   repository.getItem(id);
     
                 //   repository.add(city);
     
                    line = br.readLine();                
                }
     
     
     
     
     
     
     
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(DAOTextImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
            return repository;
     
        }
     @Override
        public void store(String filename, Repository repository) {
                try (PrintWriter output = new PrintWriter(filename)) {
     
     
               output.print(repository.toString());
     
                output.close();
     
            } catch (FileNotFoundException ex) {
                Logger.getLogger(DAOTextImpl.class.getName()).log(Level.SEVERE, null, ex);
                    }
     
            }        
     
     
     
        private String stripQuotes(String str) {
            return str.substring(1, str.length()-1);
        }
    }

    I am having problems with the above code. Whenever I run the code, all I get is:

    [] I suspect that this is due to the fact that the array is empty....i.e. is not being read properly and so returns its default value, i.e. NULL.


    Whenever I try and open a file, I get NumberFormatException. This, I suspect is due to the fact that it contains illegal characters, such as a date, floats etc.

    I am also unsure as to how I would utilise an arraylist of objects, I have two (model) classes. One class contains an ArrayList, the second class contains the member variables which are to populate the ArrayList. However, I am utterly baffled as to what I do to implement the ArrayList with the code above. I cannot convert it to String, so this means that using something like:

    ArrayList<String> result = new ArrayList<>();

    try (FileReader f = new FileReader(filename)) {
    StringBuffer sb = new StringBuffer();
    while (f.ready()) {
    char c = (char) f.read();
    if (c == '\n') {
    result.add(sb.toString());
    sb = new StringBuffer();
    } else {
    sb.append(c);
    }
    }
    if (sb.length() > 0) {
    result.add(sb.toString());
    }
    }
    return result;
    For example, won't work due to the mismatch due to string/object.



    Cab anyone please advise me? I'm totally stuck
    Last edited by Tokugawa; November 18th, 2018 at 06:03 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Whenever I run the code, all I get is:
    Where there error messages you forgot to post? Please copy and post all error messages.

    Whenever I try and open a file, I get NumberFormatException.
    Please post the error message that shows what statement the error happened on.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    There is no error message for the first issue, i.e. when creating/writing a new file. All I get is a file that has [] in it.

    When I ran:

    System.out.println("repository"+repository); is the result repository[], so evidently the code is "working", it just happens to be outputting an empty array which is NOT what I want....

    The error code that is generated whenever I open a file with my program:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
    at daos.DAOTextImpl.load(DAOTextImpl.java:60)
    at repositories.Repository.<init>(Repository.java:26)
    at controllers.WeatherDataController.<init>(WeatherDa taController.java:26)
    at weatherdataapp.WeatherDataApp.run(WeatherDataApp.j ava:22)
    at weatherdataapp.WeatherDataApp.main(WeatherDataApp. java:34)
    C:\Users\tony\AppData\Local\NetBeans\Cache\8.2\exe cutor-snippets\debug.xml:83: Java returned: 1
    BUILD FAILED (total time: 16 seconds)
    The file has the following content:
    1,"Cartagena","Spain",3
    "2015",0.2,33,26,6,"S"
    "2016",0.0,33,24,8,"SSW"
    "2017",0.0,32,25,6,"E"
    2,"Glasgow","Scotland",3
    "2015",0.0,19,8,3,"SE"
    "2016",0.1,21,11,6,"SE"
    "2017",2.1,19,11,9,"SW"

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
    at daos.DAOTextImpl.load(DAOTextImpl.java:60)
    The program tried to use an index of 4 on line 60 in an array with less than 5 elements.
    Test the length of the array to be sure it has enough elements:
      if(theArray.length > 4) // OK to use indexes 0 to 4

    I assume that the array being accessed was created by the split method. What was in the line that was split? Add a print statement just before the statement with the split that prints the contents of the line.

    I suggest that you write small test programs to work out the technical details of the problems you are having.
    That will allow you to post a complete program that shows the problem you are having.
    The current code can not be copied, compiled and executed for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    The problem is that I am being asked to do this with seperation of concern in mind, and with a MVC architecture which is complicating things.

    I am not sure how I would implement what you suggested, the


    if(theArray.length > 4) // OK to use indexes 0 to 4.

    When I have:

    public void store(String filename, Repository repository) {
    try (PrintWriter output = new PrintWriter(filename)) {
    System.out.println("blah");
    System.out.println("value of repository is"+repository);
    System.out.println("value of repository is"+repository.toString());
    System.out.println("value of repository is"+repository.toString(DELIMITER));
    output.print(repository.toString());

    output.close();

    } catch (FileNotFoundException ex) {
    Logger.getLogger(DAOTextImpl.class.getName()).log( Level.SEVERE, null, ex);
    }

    }

    I get the following output:

    value of repository is[]
    value of repository is[]
    value of repository is

    So it seems that, the array is never getting populated.

    I manually edited the array.

     
       @Override
        public Repository load(String filename) {
     
            Repository repository = new Repository();
     
            try (BufferedReader br = new BufferedReader(new FileReader(filename))) { 
                String[] temp;
                String line = br.readLine();
                while(line!=null){
                    temp=line.split(Character.toString(DELIMITER));        
                    int id = Integer.parseInt(temp[0]);
                    String cityName = stripQuotes(temp[1]);
                    String country=stripQuotes(temp[2]);
                    City city=new City (id, cityName, country);
     
     
                  repository.add(city);
     
                    System.out.println("value of repository is"+repository);
     
                    line = br.readLine();                
                }

    Still, nothing is being added to the array
    Last edited by Tokugawa; November 18th, 2018 at 08:27 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    I get the following output:

    value of repository is[]
    value of repository is[]
    value of repository is

    So it seems that, the array is never getting populated.
    What is the definition of repository? Where is anything added to it? Is the code that is supposed to add something being executed?
    What is the "array" you ask about?
       repository.add(city);
    Where is the definition of the Repository class?
    What do the add method and toString methods do.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

     
    package repositories;
     
    import daos.DAOTextImpl;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.function.Predicate;
    import model.City;
     
     
    public class Repository implements RepositoryInterface {
        private ArrayList<City> items;
      static char DELIMITER=',';    
     
        public Repository() {
            this.items = new ArrayList<>();  
     
        }
     
        public Repository(ArrayList<City> items) {        
            this.items = items;
        }
     
        public Repository(String filename) {
            this();
            // Create dao and execute load  
            DAOTextImpl dao = new DAOTextImpl();
             this.items = dao.load(filename).getItems();
        }
     
        @Override
        public ArrayList<City> getItems() {        
            return this.items;
        }
     
     
        @Override
     
     
       public void store(String filename) {       
             DAOTextImpl dao = new DAOTextImpl();
            dao.store(filename, this);
     
     
        }     
     
        @Override
        public void setItems(ArrayList<City> items) {        
            this.items = items;
        }
     
        @Override
        public void add(City item) {
            this.items.add(item);
        }
     
        @Override
        public void remove(int id) {
            Predicate<City> predicate = e->e.getId() == id;       
            this.items.removeIf(predicate);
        }
     
        @Override
        public City getItem(int id) {
            for (City item:this.items) {
                if (item.getId() == id)
                    return item;
            }
             return null;
        }
     
     
     
      @Override
      public String toString() {
           return Arrays.toString(items.toArray());
        }     
     
        public String toString(char delimiter) {  
            String output = "";
          for (City item: this.items) {
                output = output + delimiter + item;
            }
            return output;
        }

    That is the Repository class, contains the add method and toString methods. The array I am referring to is the String array, temp.









    }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Can you write a small simple program to test the Repository class?
    Add a main method to the Repository class that
    Creates an instance of the class, calls its add method and prints out the value returned by its toString method.
    Remove anything not needed for that test.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Not 100% sure how I would do that?

    So far, created a new class,

     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package model;
    import repositories.Repository;
     
    /**
     *
     * @author tony
     */
    public class NewClass {
     
       static Repository rep=new Repository();
     
     
     
    static void main(String[] args){
        {
     
            rep.add(item);
        }
    }
    }
    But being told that item cannot be found

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Add a main method to the Repository class that
    creates an instance of the class, calls its add method and prints out the value returned by its toString method.
    Remove anything not needed for the test of the add class.
    Post the complete code that can be copied, compiled and executed for testing.


    item cannot be found
    Where is item defined? It must be defined in scope for where it is used.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package model;
    import java.util.ArrayList;
    import repositories.Repository;
     
    /**
     *
     * @author tony
     */
    public class NewClass {
     
       static Repository rep=new Repository();
     
     
     
    static void main(String[] args){
        {
        ArrayList x =rep.getItems();
     
            System.out.println("value of x is"+x);
    System.out.println("hello!");
        }
    }
    }

    Ok, running that code, tells me:

    value of x is[]

    and hello, obviously

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    What happens when that code is compiled and executed? Do you get the desired results?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    I have no idea how to check the add method. It is a void method.
    Last edited by Tokugawa; November 18th, 2018 at 09:37 PM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    how to check the add method
    Call it and then print out what is returned by the toString.

    Here is the main method I added to the Repository class for testing. Also added a City class definition.
       static class City {
       }
     
       public static void main(String[] args) {
          Repository rep = new Repository();
          rep.add(new City());
          rep.add(new City());
          rep.add(new City());
          System.out.println(rep);     // [Repository$City@5ccd43c2, Repository$City@4aa8f0b4, Repository$City@7960847b]
       }
    Print out shows 3 City class objects were in the ArrayList.

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Quote Originally Posted by Norm View Post
    Call it and then print out what is returned by the toString.

    Here is the main method I added to the Repository class for testing. Also added a City class definition.
       static class City {
       }
     
       public static void main(String[] args) {
          Repository rep = new Repository();
          rep.add(new City());
          rep.add(new City());
          rep.add(new City());
          System.out.println(rep);     // [Repository$City@5ccd43c2, Repository$City@4aa8f0b4, Repository$City@7960847b]
       }
    Print out shows 3 City class objects were in the ArrayList.

    I'm done for tonight. Back tomorrow.
    How exactly did you place that code?
       static class City {
       }
     
       public static void main(String[] args) {
          Repository rep = new Repository();
          rep.add(new City());
          rep.add(new City());
          rep.add(new City());
          System.out.println(rep);     // [Repository$City@5ccd43c2, Repository$City@4aa8f0b4, Repository$City@7960847b]
       }

    Whenever I did it got numerous errors, about the class not being abstract, about methods missing etc. Reason I ask is, I was wanting to replicate that small test program for all the different possibilities because I know that there must be something that is null here. Im sorry for being so dense
    Last edited by Tokugawa; November 19th, 2018 at 07:54 AM.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    How exactly did you place that code?
    Just before the ending } of the Repository class so that it is part of the Repository class.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

     
    package repositories;
     
    import daos.DAOTextImpl;
    import java.util.ArrayList;
    import java.util.function.Predicate;
    import model.City;
     
     
    public class Repository implements RepositoryInterface {
        private ArrayList<City> items;    
     
        public Repository() {
            this.items = new ArrayList<>();       
        }
     
        public Repository(ArrayList <City> items) {        
            this.items = items;
        }
     
        public Repository(String filename) {
            this();
            DAOTextImpl dao = new DAOTextImpl();
     
     
        }
     
        @Override
        public ArrayList<City> getItems() {        
            return this.items;
        }
     
        @Override
        public void setItems(ArrayList<City> items) {        
            this.items = items;
        }
     
        @Override
        public void add(City item) {
            this.items.add(item);
        }
     
        @Override
        public void remove(int id) {
            Predicate<City> predicate = e->e.getId() == id;       
            this.items.removeIf(predicate);
        }
     
        @Override
        public City getItem(int id) {
            for (City item:this.items) {
                if (item.getId() == id)
                    return item;
            }
            return null;
        }
     
        @Override
        public String toString() {
            return "\nItems: " + this.items;
        }    
     
        @Override
        public void store(String filename) {       
            DAOTextImpl dao = new DAOTextImpl();
       dao.store(filename, this);   
     
        }
         public String toString(char delimiter) {
            String output = "";
            for (City item: this.items) {
                output += item.toString(delimiter);
            }
            return output;
        }
        static class City {
       }
     
       public static void main(String[] args) {
          Repository rep = new Repository();
          rep.add(new City());
          rep.add(new City());
          rep.add(new City());
          System.out.println(rep);     // [Repository$City@5ccd43c2, Repository$City@4aa8f0b4, Repository$City@7960847b]
       }
    }

    I get a ton of red flags doing that? :\

    "Repository is not abstract"....

    "getItem (int) cannot implement getItem in RepositoryInterface"

    to name a but a couple :\

    Have I placed it wrongly?

    Did you delete any of the code, comment it out? (I am trying to replicate exactly what you did again, sorry for being dense)

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Did you delete any of the code, comment it out?
    Yes, I got rid of almost everything except the constructor and the add and toString methods. Those are the three things that are needed to be present to test those two methods.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Finally! I got the same results as you.

    Items: [repositories.Repository$City@53e25b76, repositories.Repository$City@73a8dfcc, repositories.Repository$City@ea30797]

    So that to me, seems like hashcodes?

    Which Im very confused by, because I did have a hashcode in another class. So, I commented that hashcode method out, and ran the file again. Same result:

    Items: [repositories.Repository$City@53e25b76, repositories.Repository$City@73a8dfcc, repositories.Repository$City@ea30797]

    Previously you said;

    Print out shows 3 City class objects were in the ArrayList.

    If I run the code as follows:

     
     public static void main(String[] args) {
          Repository rep = new Repository();
          rep.add(new City());
     
          System.out.println(rep);   
       }
    }

    Only one hashcode value is returned.

    I am not sure what the hashcode values are meant to represent? Does that mean that the arraylist is null or not null?
    Last edited by Tokugawa; November 19th, 2018 at 10:44 AM.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    That test was to see if the add() method and the toString() method worked as expected. It appears that they work OK.

    repositories.Repository$City@ea30797]

    So that to me, seems like hashcodes?
    That is the String returned by the default toString() method. It has the classname followed by an @ followed by a hex value.

    If the add and toString methods work, then why does this code not do as expected in post#5:

                  repository.add(city);
     
                    System.out.println("value of repository is"+repository);
    You said the output from that println statement was
    value of repository is[]
    I can not explain that output. The add and toString methods tested OK.
    Can there be a different version of the Repository class being used?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    In truth, there are so many files...I am not sure where the hell the problem is




    City

    https://pastebin.com/unNWPQFf

    YearData

    https://pastebin.com/hZ4TrHhJ

    RepositoryInterface

    https://pastebin.com/UNjdV6zq

    DAOInterface

    https://pastebin.com/KMn2njdd

    FileReader
    https://pastebin.com/iCaXFpa2
    Last edited by Tokugawa; November 19th, 2018 at 11:11 AM.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Try some more debugging by adding some print statements to the Repository class to show the values of variables when they are changed and used. For example: print the contents of items at the end of the add method and print the contents of items at the beginning of the toString method. The print outs should show that there is something in items after add and when toString is called.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    Would that be the same process as before ?

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    No. The idea is to test the existing code as it is used and executed to find where the problem is.
    The other test was stand-alone testing of the add and toString methods.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Nov 2018
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Difficulty in creating/writing to a file (also, with reading file with data)

    I dont understand. They are void methods, even including a system.out.println statement in them doesn't generate anything. I create a main method, attempt to invoke the method, can't do so

Page 1 of 2 12 LastLast

Similar Threads

  1. File reading/writing
    By Masic1990 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 10th, 2014, 02:02 AM
  2. Reading and writing file
    By FaisalBahadur in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: June 12th, 2014, 05:38 PM
  3. Trouble with writing/reading array to/from file
    By MaximusPrime in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2012, 08:41 PM
  4. file reading & writing
    By macko in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 12th, 2011, 08:54 AM
  5. Reading a writing binary file
    By stu1811 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 30th, 2010, 12:58 PM