java中搜索代碼 java實(shí)現(xiàn)搜索框搜索功能

java如何實(shí)現(xiàn)搜索功能。比如,輸入txt就能搜索出這個(gè)文件夾內(nèi)所有txt格式的文件。請(qǐng)給完整代碼。

import?java.io.*;

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),義縣網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:義縣等地區(qū)。義縣做網(wǎng)站價(jià)格咨詢:028-86922220

public?class?FileDemo{

public?static?void?main(String[]?args)throws?Exception{

//第一個(gè)參數(shù)是文件路徑,第二個(gè)參數(shù)是要搜索的文件擴(kuò)展名

getFile("D:\\JavaDemo",".txt");

}

private?static?void?getFile(String?pathName,?final?String?endsWith)throws?Exception{

File?file?=?new?File(pathName);

if(!file.exists())

throw?new?RuntimeException("文件不存在,你檢索個(gè)P呀。");

file.listFiles(new?FileFilter(){

public?boolean?accept(File?file){

if(file.getName().endsWith(endsWith)){

System.out.println(file.getName());

return?true;

}else

return?false;

}

});

}

}

JAVA中怎么查詢代碼?

try{Connection con;\x0d\x0a Statement stmt;\x0d\x0a ResultSet rs;\x0d\x0a int temp;\x0d\x0a Class.forName("com.mysql.jdbc.Driver");\x0d\x0a con=DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","");//以上是數(shù)據(jù)庫(kù)連接,不同的數(shù)據(jù)管理器有 //不同的驅(qū)動(dòng)和鏈接方式,以上是mysql的連接\x0d\x0astmt=con.createStatement();\x0d\x0a rs=stmt.executeQuery("select * from student");//執(zhí)行查詢語(yǔ)句,結(jié)果賦值給結(jié)果集rs\x0d\x0a //結(jié)果集是結(jié)果于字段編號(hào)的映射,每一個(gè)字\x0d\x0a //段都有一個(gè)編號(hào),最小為1,也就是第一個(gè)字段 \x0d\x0a while(rs.next()){\x0d\x0a String names=rs.getString("name");//查詢結(jié)果轉(zhuǎn)換成字符串。\x0d\x0a \x0d\x0a System.out.println(names);\x0d\x0a\x0d\x0a}rs.close();\x0d\x0a }catch(Exception e){\x0d\x0a e.printStackTrace();\x0d\x0a }

求用java實(shí)現(xiàn)索引查找的代碼。

package com.cn.jdbc;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

//import java.awt.List;

public class Query {

public ListUserVo showUser(){

Connection conn=null;

Statement stmt=null;

ResultSet rs=null;

ListUserVo list=new ArrayListUserVo();

try{

conn=JDBC_Connection.getConnection();

stmt=conn.createStatement();

rs=stmt.executeQuery("select * from users");

while(rs.next()){

UserVo userVo=new UserVo();

userVo.setId(rs.getInt("id"));

userVo.setName(rs.getString("name"));

userVo.setAge(rs.getInt("age"));

userVo.setTel(rs.getString("tel"));

userVo.setAddress(rs.getString("address"));

list.add(userVo);

}

}catch(SQLException e){

e.printStackTrace();

}finally{

JDBC_Connection.free(rs, conn, stmt);

}

return list;

}

public static void main(String[] args) {

Query query=new Query();

ListUserVo list=query.showUser();

if(list!=null){

System.out.print("id\t");

System.out.print("name\t");

System.out.print("age\t");

System.out.print("tel\t");

System.out.print("address\t");

System.out.println();

for(int i=0;ilist.size();i++){

System.out.print(list.get(i).getId()+"\t");

System.out.print(list.get(i).getName()+"\t");

System.out.print(list.get(i).getAge()+"\t");

System.out.print(list.get(i).getTel()+"\t ");

System.out.print(list.get(i).getAddress()+"\t");

System.out.println();

}

}

}

}

要自己加驅(qū)動(dòng),,,,這個(gè)你應(yīng)該可以看懂吧,,

本文標(biāo)題:java中搜索代碼 java實(shí)現(xiàn)搜索框搜索功能
文章地址:http://muchs.cn/article32/dohddsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、域名注冊(cè)、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、做網(wǎng)站、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管