Login
|
Signup
langref.org
-
perl
,
java
, and
csharp
add..
all
clojure
cpp
erlang
fantom
fsharp
go
groovy
haskell
ocaml
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Files
Writing
Write a string to a file
perl
open(my $fh, '>', $path) or die "can't open $path: $!";
print $fh "This line overwites file contents!";
close $fh;
open(my $fh, '>', $path) or die "can't open $path: $!";
print $fh "This line overwites file contents!";
close $fh;
java
FileWriter fw = null;
try
{
fw = new FileWriter("test.txt");
fw.write("This line overwites file contents!");
}
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
public class SolutionXX {
public static void main(String[] args) throws IOException {
FileWriter fw = null;
try
{
fw = new FileWriter("test.txt");
fw.write("This line overwites file contents!");
}
catch (FileNotFoundException e) { System.out.println("FNF"); }
catch (IOException e) { System.out.println("IOE"); }
catch (Exception e) { System.out.println("E"); }
finally { if (fw != null) fw.close(); }
}
}
java
PrintWriter pw = null;
try
{
pw = new PrintWriter(new BufferedWriter(new FileWriter("test.txt")));
pw.print("This line overwites file contents!");
}
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.IOException
public class SolutionXX {
public static void main(String[] args) throws IOException {
PrintWriter pw = null;
try
{
pw = new PrintWriter(new BufferedWriter(new FileWriter("test.txt")));
pw.print("This line overwites file contents!");
}
catch (FileNotFoundException e) { System.out.println("FNF"); }
catch (IOException e) { System.out.println("IOE"); }
catch (Exception e) { System.out.println("E"); }
finally { if (pw != null) pw.close(); }
}
}
csharp
System.IO.File.WriteAllText("filename.txt", "Some text to write to the file");
System.IO.File.WriteAllText("filename.txt", "Some text to write to the file");
Submit a new solution for
perl
,
java
, or
csharp
There are 15 other solutions in
additional
languages (
clojure
,
cpp
,
erlang
,
fantom
...)