- 함수 WriteAllText()
- 함수 file_put_contents()
1 Bash[ | ]

Bash
Copy
echo "John Smith" > test.txt
cat test.txt
# John Smith
2 CMD[ | ]
Bash
Copy
echo John Smith > test.txt
type test.txt
REM John Smith
3 C#[ | ]

C#
Copy
System.IO.File.WriteAllText(@"test.txt", "John Smith");
C#
Copy
StreamWriter sw = new StreamWriter("test.txt");
sw.Write("John Smith");
sw.Close();
4 Go[ | ]

Go
CPU
-1.0s
MEM
-0M
-1.0s
Copy
package main
import (
"fmt"
"os"
)
func WriteAllText(filePath string, text string) (err error) {
f, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("error on Create: %w", err)
}
defer f.Close()
_, err = f.WriteString(text)
if err != nil {
return fmt.Errorf("error on WriteString: %w", err)
}
return nil
}
func main() {
err := WriteAllText("hello.txt", "Hello, 世界")
if err != nil {
panic(err)
}
fmt.Println("ok")
}
ok
5 Java[ | ]

Java
Copy
BufferedWriter bw = new BufferedWriter( new FileWriter( "test.txt" ) );
bw.write( "John Smith" );
bw.close();
Java
Copy
PrintWriter pw = new PrintWriter( "test.txt" );
pw.println( "John Smith" );
pw.close();
Java
Copy
PrintWriter pw = new PrintWriter( new FileWriter( "test.txt" ) );
pw.println( "John Smith" );
pw.close();
6 Lua[ | ]
lua
Copy
s = 'His name is\nJohn Smith'
f = io.open('test.txt','w')
f:write(s)
f:close()
7 PHP[ | ]

PHP
Copy
file_put_contents("test.txt", "John Smith");
8 Python[ | ]
Python
Copy
s = 'His name is\nJohn Smith'
f = open('name.txt', 'w')
f.write(s)
f.close()
with open('name.txt') as f2: print( f2.read() )
# His name is
# John Smith
Python
Copy
s = 'His name is\nJohn Smith'
with open('name.txt', 'w') as f:
f.write(s)
with open('name.txt') as f2: print( f2.read() )
9 Perl[ | ]
Perl
Copy
my $s = "His name is\nJohn Smith";
open my $fh, ">", 'name.txt';
print $fh $s;
close $fh;
10 같이 보기[ | ]
로그인하시면 댓글을 쓸 수 있습니다.
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ―Pinkcrimson
유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong