File file = new File(this.getClass().getResource("").getPath()); System.out.println(file.getPath()); String path=file.getPath(); String filename="test1.txt"; //path=path.substring(0,path.indexOf("WEB-INF"))+"upload\\Excel"+"\\"+"import.txt"; //服务器专用 username= DesUtil.encrypt(username); password=DesUtil.encrypt(password); ip=DesUtil.encrypt(ip); DatabaseName=DesUtil.encrypt(DatabaseName); path=path.substring(0,path.indexOf("target"))+"src\\main\\webapp\\upload\\Excel"+"\\"+"import.txt"; clearInfoForFile(path); try { FileWriter fileWriter =new FileWriter(path, true); String info=""; info=info+ip+"\n"+DatabaseName+"\n"+username+"\n"+password; fileWriter.write(info); fileWriter.flush(); fileWriter.close(); }catch (IO
java io流清空txt文件内容及填充文件内容
最新推荐文章于 2022-06-02 16:08:12 发布
该博客介绍了如何使用Java的IO流来清空一个TXT文件的内容,并填充新的数据。首先,通过File类获取文件路径,然后使用FileWriter在追加模式下写入信息,包括加密后的IP、数据库名、用户名和密码。接着,提供了一个`clearInfoForFile`方法,用于清空指定文件的内容。最后,展示了读取文件内容的代码片段。
摘要由CSDN通过智能技术生成