Solved

Question with writing to files

Posted on 2002-07-01
6
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 67
maven disable workspace resolution 1 75
jmeter usage 4 61
Strange router problem - can't access hotmail.com 14 108
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

734 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