• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NextLine makes me sad

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey =) I am a little bit stuck here =)

I have this file that I want to scan that contains some data. Such as

12-Jan-2012,815,847.5,849.5,804.55,658784
11-Jan-2012,799.5,812,818,796.5,634561

etc.


I need to scan the file and print it to console. But at first its ok but at the end I get an error

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at readfile.readFile(readfile.java:25)
at Test.main(Test.java:9)


I think it is something to do with my usage of Scanner.nextLine method.... Could someone help me out? Here is my code...







And another question if I may =)

I need to save this data as a separate file which should be an HTML template. I have really no clue how to do that, or if it is even possible =)

It is my first post btw If those are really nooby questions please dont be too harsh on me
 
Fred Dubrovskiy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOLVED

Posting the code here in case anyone will have the same problem in the future




credit to ilyagetready
 
Fred Dubrovskiy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another problem I face is how to get this from consol into another text document. Would appreciate any help. This is what I came up with so far.

 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Another problem I face is how to get this from consol into another text document. Would appreciate any help. This is what I came up with so far.


And what exactly is the problem you are facing? You need to be more specific and TellTheDetails so we can help you.

The only thing that I see might be wrong with your code is that the path you are using to write to a file is not correct. There is a drive missing at the beginning, meaning that your other methods shouldn't work too.

Also make sure you follow the naming convention. Class names are written in camel case, starting with a capital letter; methods start with a lower letter as well as variables.
 
Fred Dubrovskiy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you =) Will try and follow the naming conventions in the future =)

The pathways all should be correct - as I am working on a mac. The other method work just fine with those pathways.

What I am wanting to do is to create a java program to read data from a .txt file and create a web page presenting this information in a suitable format.

So far I have managed to open the file and present all the data to appear on the console. Now what I willing to do is to create a method to be able to put all those lines from the console and create a new .txt document with them. This is what I think should be responsible for this action - but it is not working =(

My next step would be writing a webpage template onto which I will hopefull to rewrite the data again.

 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My mistake, I thought it's a Windows path.

How about you check if an exception occurs and print the stack trace at that catch block. Then post it here.
 
Fred Dubrovskiy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesnt want to show at all and nothing gets printed out.Perhaps I should rephrase myself.

So far I have lines of such code in the console



I want to know how to make a method to scan this code and make a new .txt file out of it.

 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A sidenote: if you run the program with the standard output redirected into a file, then the System.out... stuff will go there.
I think this works with the Apple command line (is it maybe bash?) as well:

java -classpath myclasspath myoptions myprogram myarguments >file
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic