www.pudn.com > file_j2me.rar > file.java


    String word_input = "wrap"; 
	String word_search = null; 
	 
	private void search () 
	{ 
		InputStream in = null; 
		byte[] buffer1 = new byte[259737]; 
		byte[] word = new byte[20]; 
		//System.out.println(word.length); 
		int kk = 0; 
		int position = 0; 
		int line = 1; 
		int temp_line = 100000; 
		int flag = 0; 
		try 
		{ 
			word = word_input.getBytes(); 
			//System.out.println(word.length); 
			in = getClass().getResourceAsStream("/cet4.txt"); 
			in.read(buffer1); 
			//System.out.println(buffer1.length); 
			in.close();			 
		} 
		catch (Exception e) 
		{ 
			System.out.println("error!"); 
		} 
		for (int ii = 0; ii < buffer1.length - 20; ii++) 
		{ 
			if (buffer1[ii]  == '\n') 
			{ 
				line++; 
			} 
			for (int jj = 0; jj < word.length; jj++) 
			{ 
				if (buffer1[ii + jj] == word[jj]) 
				{ 
					kk++; 
				} 
			} 
			if (kk == word.length) 
			{ 
				if (flag == 0) 
				{ 
				 
					position = ii; 
					try 
					{ 
						word_search = new String(buffer1, position, word.length, "UTF-8"); 
					} 
					catch (Exception e) 
					{ 
						System.out.println("new string() error"); 
					} 
					System.out.println(word_search); 
					System.out.println(line); 
					temp_line = line; 
					//break; 
					flag ++ ; 
				} 
			} 
			else 
			{ 
				kk = 0; 
			} 
			if (line == temp_line + 1) 
			{ 
				try 
				{ 
					word_search = new String(buffer1, position + word.length + 1, ii - position - word.length - 2, "UTF-8"); 
				} 
				catch (Exception e) 
				{ 
				} 
				System.out.println(word_search); 
				break; 
			} 
			if (ii == buffer1.length - 21) 
			{ 
				System.out.println("no word"); 
				break; 
			} 
		} 
 
	} // search() end!!!