Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Newbi Question about importing files

Status
Not open for further replies.

nshenry03

Technical User
Feb 9, 2006
60
US
I'm trying to randomly import a file that has a Sudoku puzzle in it into an array and then import its answers into another array. I'm getting the random number beforehand and passing it into the function GetCharactersFromFile. Both Files are located in different dirs b/c they have the same file name so that they can be easily matched.

Code:
public void GetCharactersFromFile(int a)
{
FileReader inputStream = null;
FileWriter outputStream = null;

try {
inputStream = new FileReader("SourceFiles\\puzzles\\1.txt");
outputStream = new FileWriter("SourceFiles\\solns\\1.txt");
...

Right now I just have files that I know exist so I can get it to work for now

I am getting error:
"Unhandled exception type FileNotFoundException" for puzzles
"Unhandled exception type IOException" for solns"

I've tried \, \\, /, //, everything I can think of, including the full path from the root /home/nhenry/..., but that didn't work and I'd like to avoid full path b/c I'm going to have to turn in to a teacher who is using windows

any help would be appreciated
 
That's not because of the path. Are you catching the exceptions that show in the message, you should include them in the try..catch block.

Cheers,
Dian
 
\ is wrong, because it is a special character, which needs masking
\\ might work on windows-system, but isn't portable
// is complete nonesense
/ is the way to go - will work on windows, linux, mac, solaris.

Are you taking care of upper/lowercase?
Can you show the output of the command
ls /home/nhenry/.../SourceFiles/puzzles/1.txt
with additional directories replacing the dots?

don't visit my homepage:
 
Just a note on file separators ...

Use :

String filename = "Mydir" +File.separator +"myfile.txt";



--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top