Your program should consist of at least three classes. A main class, a board class, and a move class. We'll describe these in turn.
long t = System.timeMillis(); while (System.timeMillis() - t < 50) {}A nice addition to the program would be to include a Slider so that the user can control the speed.
Your board should be easy to read. Numbers that are given in the file should be easily distinguished from those the program figures out (e.g. use different colors). It is also nice to distinguish the various sectors of the board (chunks of 9 squares).
For the search itself we will want to use depth-first search. This is because the space required for breadth-first search is too large for a computer (the branching factor of the search is 9, with a depth of about 70 for a typical game). We're going to use a slight variant of the depth-first search that we have been talking about. In this version you only have one copy of the state which you continually modify. The trick is to figure out what moves you have made, what move comes next, and when you have to backtrack, how to do that. To figure out the moves you have made we'll use a Stack. Everytime you make a move (fill in a square) you simply push the move onto the Stack (Move, therefore, is a triple of row, col, number). To undo a move you pop it from the Stack. Since we're using brute-force search determining the next move at that point is simple. Let's say you popped off the Move (3, 5, 7). Our strategy will be to simply try moves starting at 1 and going up to 9. So you would next try (3, 5, 8). Your Board class should take care of the details.
Move nextMove(int startNumber)takes the current board and gets the next move (when possible). Returns the Move. If no legal move is available at the next square it returns an empty Move (0, 0, 0). The empty Move is a signal to your main class that it should backtrack (by popping the stack).
To figure out the next square to move to you can use any pattern, e.g. just start at the top left corner and search for the first open square moving left to right and top to bottom. Once you find an open square you must check to see if a legal number can be put onto that square. The legal number must be at least of value "startNumber". When an empty Move is returned that is a signal for the main class to backtrack (pop the Stack). The parameter specifies what to start with (normally 1, but when backtracking can be larger).
boolean isDone()returns true when the Board has finished.
boolean moveOk(Move move)checks if putting the value into the corresponding square is legal. This is really the crucial function for speed. It is paramount that you do this as efficiently as possible.
I also suggest you have getters and setters for individual board squares.
public void readBoard(String fileName) { File f = new File(fileName); Scanner sc = null; try { sc = new Scanner(f); } catch (FileNotFoundException e) { System.err.println("File not found!"); System.exit(0); } while (sc.hasNextInt()) { int nextOne = sc.nextInt(); } }In a nutshell, the code creates a new File, then opens the file up with the Scanner class. Because this process is fraught with error it is checked for an exception to make sure everything went ok. Once it has been opened, then the Scanner can basically act as an interator.
Start with a pre-defined board and fill it up with convenient values. Then find the solution. Only after you tested this, add the scanner, and the functionality that the board can be read from a file.