[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Question with writing to files

I want to know how to create text files with variable names.

For instance, let's say I want to create a text file called "File0".  Later I want to create a text file called "File1", and so on.

How would I create a file that has a variable in it's name that I can just keep incrementing?

I hope you guys understand what Im asking :)
0
lwinkenb
Asked:
lwinkenb
  • 3
  • 3
1 Solution
 
objectsCommented:
int n = 5;
File f = new File("File"+n);
0
 
lwinkenbAuthor Commented:
Thanks objects.

How would I do the same thing for variable names?  Let's say I wanted to make a bunch of integers like

int integer0 = someRandomNumber;
int integer1 = someRandomNumber;
int integer2 = someRandomNumber;
...
0
 
objectsCommented:
you can't sorry.
Why not use an array instead:
int[] integer = new int[3];
integer[0] = someRandomNumber;
integer[1] = someRandomNumber;
integer[2] = someRandomNumber;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lwinkenbAuthor Commented:
Thanks objects.

How would I do the same thing for variable names?  Let's say I wanted to make a bunch of integers like

int integer0 = someRandomNumber;
int integer1 = someRandomNumber;
int integer2 = someRandomNumber;
...
0
 
lwinkenbAuthor Commented:
Thanks again!
0
 
objectsCommented:
No worries, thanks for the points :)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now