Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 51
Like Tree5Likes

Thread: Writing file input in a matrix

  1. #21
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Norm View Post
    What was the variable that you printed out?
    The Scanner class is used to read a String into a variable: currentLine
    What was the contents of that variable after you read something into it using the Scanner class?
    when i print the currentline it just gives me my filepath, what makes me think that in stead of reading the file, it just reads the filepathname, which would explain why my height is still at 1... so i guess there's my mistake.

  2. #22
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Quote Originally Posted by diamonddragon View Post
    Does it?
    I thought it creates a new File instance.
    I though so, I could be wrong, I've only been working with Java for 4 months.

  3. #23
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Writing file input in a matrix

    Time to read the API doc for the Scanner class to see what the choices for constructors are. The Scanner class can be used in many ways.
    Java Platform SE 6

  4. #24
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Neovenator View Post
    I though so, I could be wrong, I've only been working with Java for 4 months.
    Thats not important.
    You should consider using File instance, that You created, when creating new Scanner.
    And what this supposed to do?
    Java Code:
    myArray[i][j] = (char)br.read();

  5. #25
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Norm View Post
    Time to read the API doc for the Scanner class to see what the choices for constructors are. The Scanner class can be used in many ways.
    Java Platform SE 6
    wow problem solved :D Thanks a million!! really ;) it was really a dumb mistake :s

  6. #26
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Quote Originally Posted by diamonddragon View Post
    Thats not important.
    You should consider using File instance, that You created, when creating new Scanner.
    And what this supposed to do?
    Java Code:
    myArray[i][j] = (char)br.read();
    And what u mean, using fileinstance? uhm that code should read the chars one by one in my matrix.

  7. #27
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Now that i get the correct height and width, I get another problem, this is my output when I print out my matrix :

    Java Code:
                           #
                         #####
    
                        #######
                       ########
    #              #
                     ############           
     ##
                   ################         ###
      B     
        ####################       ####         A
    ###########
    ###############################################￿￿￿￿￿￿￿￿￿￿￿
    ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿
    ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿
    ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿
    ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿
    ￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿

  8. #28
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Writing file input in a matrix

    Quote Originally Posted by diamonddragon View Post
    Thats not important.
    You should consider using File instance, that You created, when creating new Scanner.
    And what this supposed to do?
    Java Code:
    myArray[i][j] = (char)br.read();
    It's pretty clear what the OP is doing here.
    Indeed they've explained it.
    As for your FileInputStream question, I think you are confusing the OP more...it does not "create a new file".
    It opens a stream to an existing file. If the file does not exist it throws an exception.

    If you can't help it might be an idea to back out.

  9. #29
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Neovenator View Post
    Now that i get the correct height and width, I get another problem, this is my output when I print out my matrix :
    This was going to be my next possibility.
    Your Scanner is reading lines, after stripping out the new line character (which maybe 1 or 2 characters depending on the system).
    Your buffered reader on the other hand...

    Have you thought about using the BufferedReaders readLine() method and then spreading the chars around?

  10. #30
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Tolls View Post
    It's pretty clear what the OP is doing here.
    Indeed they've explained it.
    As for your FileInputStream question, I think you are confusing the OP more...it does not "create a new file".
    It opens a stream to an existing file. If the file does not exist it throws an exception.

    If you can't help it might be an idea to back out.
    Did I say it creates a new file, or it creates new File instance?
    Can You see difference?

  11. #31
    Neovenator is offline Member
    Join Date
    Jan 2012
    Posts
    17
    Rep Power
    0

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Tolls View Post
    This was going to be my next possibility.
    Your Scanner is reading lines, after stripping out the new line character (which maybe 1 or 2 characters depending on the system).
    Your buffered reader on the other hand...

    Have you thought about using the BufferedReaders readLine() method and then spreading the chars around?
    I'll try that :D thank you

  12. #32
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Writing file input in a matrix

    Quote Originally Posted by diamonddragon View Post
    Did I say it creates a new file, or it creates new File instance?
    Can You see difference?
    Which means what in this context?
    It's pretty irrelevant what FIS does under the hood, other than knowing it opens a stream to a file.
    This is all a bit confusing now as to what you're getting at...

  13. #33
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Neovenator View Post
    I'll try that :D thank you
    Good luck and post again with the new code if you hit a problem.

  14. #34
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Tolls View Post
    Which means what in this context?
    It's pretty irrelevant what FIS does under the hood, other than knowing it opens a stream to a file.
    This is all a bit confusing now as to what you're getting at...
    No need reacting in the way "back out", cause I'm also trying to learn something, since this is my 3rd week of learning Java.
    I made mistake when saying new File instance, cause my point was that FileInputStream can not be created by using "YourFile" as argument, cause it is not valid file path.
    What I meant to say is that FileInputStream should be created with new File instance as an argument.

  15. #35
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Writing file input in a matrix

    FileInputStream can not be created by using "YourFile" as argument, cause it is not valid file path.
    Check the API doc. Why can't you read from a file named: "YourFile"?
    Fubarable likes this.

  16. #36
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Writing file input in a matrix

    Quote Originally Posted by diamonddragon View Post
    No need reacting in the way "back out", cause I'm also trying to learn something, since this is my 3rd week of learning Java.
    Do you think that perhaps you should hold off giving help til you know a little bit more? Most newbies read your advice and don't realize that it's coming from someone who's a complete novice to the language.

  17. #37
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Norm View Post
    Check the API doc. Why can't you read from a file named: "YourFile"?
    Because "YourFile" is not valid file path.
    But, "YourFile.txt" or "YourFile.dat" would do the job.

  18. #38
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Writing file input in a matrix

    try it and let us know what happens. Extensions are NOT required

  19. #39
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Writing file input in a matrix

    Quote Originally Posted by Fubarable View Post
    Do you think that perhaps you should hold off giving help til you know a little bit more? Most newbies read your advice and don't realize that it's coming from someone who's a complete novice to the language.
    You can not forgive this little confusion?
    Didn't I edited my incorect post saying about mistake?
    How is man supposed to learn but not by making mistakes and finding correct answers?

  20. #40
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Writing file input in a matrix

    How is man supposed to learn but not by making mistakes and finding correct answers?
    Yes I agree that that is a good way to do it. However you are hijacking another OPs thread and potentially confusing him.

    There is no restriction for you to start your own thread with your own questions.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 14
    Last Post: 07-15-2011, 05:22 AM
  2. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  3. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  4. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  5. Replies: 9
    Last Post: 07-10-2008, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •