• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Reading a file line by line , file path

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I am trying to read a file line by line and I am  using this code:


I am getting the filename via args[0] and my question is if always only the filename is passed, will it always try to get the file from the executing directory of the compiled jar file ?
Thank you in advance for an answer !
 
Sheriff
Posts: 17105
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

When posting code, please UseCodeTags (←click that, it's a link)
 
Saloon Keeper
Posts: 9561
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Ocean wrote:I am getting the filename via args[0]


No, you are not. You are passing in the whole array, not just one element.
 
Carey Brown
Saloon Keeper
Posts: 9561
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This won't even compile. Could you work out the compilation issues first? If you get stuck then cut and past THE ENTIRE error message here along with a current copy of the state of your code.
 
Adam Ocean
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Adam Ocean wrote:I am getting the filename via args[0]


No, you are not. You are passing in the whole array, not just one element.



Thank you, that was a typo. But my question concerning the path is still not answered.
 
Adam Ocean
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:This won't even compile. Could you work out the compilation issues first? If you get stuck then cut and past THE ENTIRE error message here along with a current copy of the state of your code.



Now it compiles. Thank you for the advice.
 
Carey Brown
Saloon Keeper
Posts: 9561
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could write a little test program to find out.
 
Adam Ocean
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:You could write a little test program to find out.



I compiled it with jdk 11 and tested the jar file with windows 10 and ubuntu linux. I always get the path from where I execute the jar file. So can I make the assumption that this always work ?
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic