-
filenotfoundexception :@
import java.io.*;
import java.util.*;
public class xxx{
static BufferedReader input = new BufferedReader(new FileReader("C:\\Documents and Settings\\Omar\\Desktop\\pages.txt"));
static int number, pointer = 0, i = 0, j = 0;
static int array[][];
//static int a[] = {1,2,3,2,4,5};//,9,1,3,4,2,0,1,2,3,3,3,2,6,7};
static boolean exist = false;
static String num;
static StringTokenizer st;
public static void main(String args[]) throws IOException
{
num = input.readLine();
a = new int[Integer.parseInt(num)];
num = input.readLine(); /*this line says there are 20 pages. i ignored this number because
*am going to use a string tokenizer to take them one at a time.
*/
num = input.readLine();
st = new StringTokenizer(num);
while (st.hasMoreTokens())//for (int i = 0; i < a.length; i++)
{
number = Integer.parseInt(st.nextToken());//)a[i];
for (j = 0; j < array[0].length; j++)
{
if (number == array[0][j])
{
exist = true;
if (array[1][j] == 0)
array[1][j] = 1;
break;
}
}
if (!exist)
{
for (int d = 0; d < array.length; d++)
{
if (array[1][pointer] == 0)
{
array[0][pointer] = number;
array[1][pointer] = 1;
pointer++;
if (pointer == array[0].length)
pointer = 0;
break;
}
else
{
pointer++;
if (pointer == array[0].length)
pointer = 0;
}
}
}
exist = false;
}
input.close();
for (int i = 0; i < array[0].length; i++)
System.out.print(array[0][i] + " ");
}
}
can some plz tell me how they insert code here wihtout it lookin gas horrible as it does here? SORRY!
ok so if you run this prg u'll get an error of hte title of this topic. WHY? the txt file is right next to the java file. it worked before. i dont no why am getting this error now. its been driving me crazy. plz someone tell me why its wrong
oh and pay no attention to the code. it works but it needs umm better organization.
-
Hi ,
I have not gone thru the code fully.U tell me what u want to do here.But File declaration needs filenotfound exception to be catched.
So u remove the static keyword and bring this static BufferedReader input = new BufferedReader(new FileReader("C:\\Documents and Settings\\Omar\\Desktop\\pages.txt"));
inside main method.It will stop the exception.
-
thanx a lot! so can you plz explain again why is it that it didnt work and needed tob moved to my method?
we learned about the clock procedure. something about how our processor handles our files; pages and memory management.
this prg simulates how page swapping takes place
u have an array of x frames (first line in txt file is a number indicating the size of the array)
ignore second line of txt
third line has a bunch of pages that i need to enter into this array
so i take a page and i search for it in the array. if i dont have it then i start searching from where the pointer is until i went through the entire array looking for a page whose bit is 0. when i find it. i swap the current page with this new one and change hte bit to 1.
however if page does exist in array then it checks the bit. if its 0 it turns it to 1. if 1 it does nothing.