import javaioFile;
import javaioFileNotFoundException;
import javaioFileReader;
import javaioFileWriter;
import javaioIOException;
import javaioPrintWriter;
public class Day02_B {
static String path="K:/Test/Nametxt";//路径
public static void main(String[] args) {
File fileText=new File(path);//文件
if(fileTextcanExecute()) //如果文件存在就继续
setText(fileText,"刚","xx");//“刚”指定改为:“XX”
}
private static void setText(File fileText,String target,String src) {//修改
BufferedReader br=null;
PrintWriter pw=null;
StringBuffer buff=new StringBuffer();//临时容器!
String line=SystemgetProperty("lineseparator");//平台换行!
try {
br=new BufferedReader(new FileReader(fileText));
for(String str=brreadLine();str!=null;str=brreadLine()) {
if(strcontains(target))
str=strreplaceAll(target,src);
buffappend(str+line);
}
pw=new PrintWriter(new FileWriter(fileText),true);
pwprintln(buff);
} catch (FileNotFoundException e) {
eprintStackTrace();
}catch (IOException e) {
eprintStackTrace();
}finally {
if(br!=null)
try {
brclose();
} catch (IOException e) {
eprintStackTrace();
}
if(pw!=null)
pwclose();
}
}
}
需要用update语句来进行修改。
update语句基本语法:
update 表名 set 字段='值' where 条件;如test表中有如下数据:
现在要将ID=3的这条数据的NAME改成badkano,可用如下语句:
commit;
运行后的结果:
说明:
update语句执行后,必须commit来提交,否则只在当前session中有效。
FileStream fs = new FileStream("d:\\atxt", FileModeOpen);StreamReader m_streamReader = new StreamReader(fs);
m_streamReaderBaseStreamSeek(0, SeekOriginBegin);
string arry = "";
string strLine = m_streamReaderReadLine();
do
{
//你把查询换成试用你的就行了
string[] split = strLineSplit('=');
string a = split[0];
if (aToLower() == "ip")
{
arry += strLine + "\n";
}
strLine = m_streamReaderReadLine();
} while (strLine != null && strLine != "");
m_streamReaderClose();
m_streamReaderDispose();
fsClose();
fsDispose();
ConsoleWrite(arry);
ConsoleReadLine();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)