echo "John Smith" > test.txt
cat test.txt
# John Smith
echo John Smith > test.txt
type test.txt
REM John Smith
System.IO.File.WriteAllText(@"test.txt", "John Smith");
StreamWriter sw = new StreamWriter("test.txt");
sw.Write("John Smith");
sw.Close();
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")
}
BufferedWriter bw = new BufferedWriter( new FileWriter( "test.txt" ) );
bw.write( "John Smith" );
bw.close();
PrintWriter pw = new PrintWriter( "test.txt" );
pw.println( "John Smith" );
pw.close();
PrintWriter pw = new PrintWriter( new FileWriter( "test.txt" ) );
pw.println( "John Smith" );
pw.close();
s = 'His name is\nJohn Smith'
f = io.open('test.txt','w')
f:write(s)
f:close()
file_put_contents("test.txt", "John Smith");
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
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() )
my $s = "His name is\nJohn Smith";
open my $fh, ">", 'name.txt';
print $fh $s;
close $fh;