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

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

例如,我在代碼中寫了如下內(nèi)容

例如,我在代碼中寫了如下內(nèi)容

C++
富國滬深 2023-01-12 19:15:30
void main(){printf("你好");system("ping 127.0.0.1");printf("再見");}如何將“你好”和“再見”打到屏幕上,將ping的信息打到"ping.result"文件里?
查看完整描述

2 回答

?
慕容森

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

可以利用重定向?qū)崿F(xiàn)system函數(shù)輸出到文件。
例如:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

public class Test {
publicstaticvoid main(String[] args) {

PrintStream printStream = null;
PrintStream sysout = System.out;
PrintStream syserr = System.err;
try {
File file = new File("c:\\systemout.log");

if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
printStream = new PrintStream(new FileOutputStream(new File(
"c:\\systemout.log"),true));

// set output to file instead of console
System.setOut(printStream);
System.setErr(printStream);
System.out.println("Before Redirect:System.out.println");
System.err.println("Before Redirect:System.err.println");
} catch (FileNotFoundException e) {
//TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (printStream !=null) {
printStream.close();
}
// Reset the output to console
System.setOut(sysout);
System.setErr(syserr);

System.out.println("After Redirect:System.out.println");
System.err.println("After Redirect:System.err.println");
}

}


查看完整回答
反對(duì) 回復(fù) 2023-01-15
?
不負(fù)相思意

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

最簡單的方法就是利用重定向?qū)崿F(xiàn)


system("ping 127.0.0.1 >xxxx");//xxxx為要寫入的文件名,包括路徑


查看完整回答
反對(duì) 回復(fù) 2023-01-15
  • 2 回答
  • 0 關(guān)注
  • 88 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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