Solved

Question with writing to files

Posted on 2002-07-01
6
190 Views
Last Modified: 2010-03-31
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
Comment
Question by:lwinkenb
  • 3
  • 3
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7123381
int n = 5;
File f = new File("File"+n);
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 7123430
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
 
LVL 92

Expert Comment

by:objects
ID: 7123438
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:lwinkenb
ID: 7123451
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
 
LVL 5

Author Comment

by:lwinkenb
ID: 7123708
Thanks again!
0
 
LVL 92

Expert Comment

by:objects
ID: 7123717
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question