• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rename a File and Change Number in File  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I have this notepad file name:
Company_XXX_768_JGH.txt
Contents:

Random Text

Blah Blah Blah

Network ID: 768


I need to change the file name JGH number to 771 AND change the network id to 771.

And I'll need to do this for multiple files in the future with a number that goes up. So in the future rename Network IDs to 772, 773,774, etc.

Any thoughts? I know to use java.nio.file and I know how to rename a simple text file. Just want to get started on this next step.
 
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the file line by line
 
Shaman Dasuta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked on some coding and got this so far:



So the key thing is this outputs:

true
This line has the Number!: true
ID Number: 80801568


So now I just need to remove 1568 from 80801568 and add on my own 4 digit number. Which set of commands can do this?
How can I just get the number I want from that line?
 
Shaman Dasuta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I can get the last 4 numbers as a string with this:



Now I just need to subtract that from my original string and add a new number set.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!