第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將字符串存儲(chǔ)在 .txt 文件中,同時(shí)不清除該文件中已有的內(nèi)容 java

如何將字符串存儲(chǔ)在 .txt 文件中,同時(shí)不清除該文件中已有的內(nèi)容 java

忽然笑 2021-09-12 16:08:43
我目前擁有的是這個(gè)import java.io.*;import java.security.acl.NotOwnerException;import java.util.Scanner;class Main {  public static void main(String args[])  {      try{    System.out.print("Enter username: ");    Scanner scanner = new Scanner(System.in);    String username = scanner.nextLine();    System.out.print("Enter email: ");    Scanner scanner2 = new Scanner(System.in);    String email = scanner.nextLine();    System.out.print("Enter password: ");    Scanner scanner3 = new Scanner(System.in);    String password = scanner.nextLine();    // Create file     FileWriter fstream = new FileWriter("username.txt");        BufferedWriter out = new BufferedWriter(fstream);    out.write(username + ":" + email + ":" + password);    //Close the output stream    out.close();    }catch (Exception e){//Catch exception if any      System.err.println("Error: " + e.getMessage());    }  }}但它一直在清除第一行。有沒(méi)有辦法讓它每次都添加一行而不是清除第一行?如果可以,請(qǐng)有人幫助我。我正在為 java 使用 repl.it。
查看完整描述

1 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

您需要打開(kāi)帶有附加標(biāo)志的文件為真。


FileWriter fstream = new FileWriter("username.txt",true);

    BufferedWriter out = new BufferedWriter(fstream);

out.write("\n" + username + ":" + email + ":" + password);

這將確保附加文件中的內(nèi)容。此外,“\n”將確保每一行都打印在文件的新行上。


查看完整回答
反對(duì) 回復(fù) 2021-09-12
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)