C#, 118 112 98 bytes
Golfed
void M(){var f=new FileInfo("_");var s=f.CreateText();s.Write("Hello World");s.Flush();s.Close();}
Ungolfed
public void M() {
var f = new FileInfo( "_" );
var s = f.CreateText();
s.Write( "Hello World" );
s.Flush();
s.Close();
}
Full explicit code
using System.IO;
namespace N {
class C {
public void M() {
// A file name is required
FileInfo f = new FileInfo( "_" );
// Obtain the Stream to later write on it
StreamWriter s = f.CreateText();
// Write 'Hello World' to the Stream
s.Write( "Hello World" );
// Flush it to the file
s.Flush();
// Close the Stream, for security and integrity reasons.
s.Close();
}
}
}
Releases
- v1.2 -
-14 bytes
- Changed to var
s. Shoutout to Jean Lourenço.
- v1.1 -
-6 bytes
- Simplified names.
- v1.0 -
118 bytes
- Initial solution.
I'll leave a version down below that only uses the Console to write on th file. Just because I can.
C# Console Version, 39 bytes
Golfed
void M(){Console.Write("Hello World");}
Ungolfed
public void M() {
Console.Write("Hello World");
}
Full code
using System;
namespace N {
class C {
public void M() {
// Write 'Hello World' to the output handler
Console.Write("Hello World");
}
}
}
Usage
<Exe. file name>.exe > FileToOutput.txt
Releases
- v1.0 -
39 bytes
- Initial solution.