⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.java

📁 j2me中读写文件查找的实例
💻 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!!!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -