WeixiangYan/CodeTransOcean huggingface dataset:
Task: File input_output

C: #include <stdio.h>

int main(int argc, char **argv) {
  FILE *in, *out;
  int c;

  in = fopen("input.txt", "r");
  if (!in) {
    fprintf(stderr, "Error opening input.txt for reading.\n");
    return 1;
  }

  out = fopen("output.txt", "w");
  if (!out) {
    fprintf(stderr, "Error opening output.txt for writing.\n");
    fclose(in);
    return 1;
  }

  while ((c = fgetc(in)) != EOF) {
    fputc(c, out);
  }

  fclose(out);
  fclose(in);
  return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output


C++: #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    string line;
    ifstream input ( "input.txt" );
    ofstream output ("output.txt");
    
    if (output.is_open()) {
        if (input.is_open()){
            while (getline (input,line)) {
                output << line << endl;
            }
            input.close(); 
        }
        else {
            cout << "input.txt cannot be opened!\n";
        }
        output.close(); 
    }
    else {
        cout << "output.txt cannot be written to!\n";
    }
    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output




Go: package main

import (
    "fmt"
    "io/ioutil"
)

func main() {
    b, err := ioutil.ReadFile("input.txt")
    if err != nil {
        fmt.Println(err)
        return
    }
    if err = ioutil.WriteFile("output.txt", b, 0666); err != nil {
        fmt.Println(err)
    }
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output





Java: import java.io.*;

public class FileIODemo {
  public static void main(String[] args) {
    try {
      FileInputStream in = new FileInputStream("input.txt");
      FileOutputStream out = new FileOutputStream("ouput.txt");
      int c;
      while ((c = in.read()) != -1) {
        out.write(c);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e){
      e.printStackTrace();
    }
  }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output







Python: import shutil
shutil.copyfile('input.txt', 'output.txt')





Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output








VB: Sub WriteToFile(input As FolderItem, output As FolderItem)
  Dim tis As TextInputStream
  Dim tos As TextOutputStream
  tis = tis.Open(input)
  tos = tos.Create(output)
  While Not tis.EOF
    tos.WriteLine(tis.ReadLine)
  Wend
  tis.Close
  tos.Close
End Sub




Ada: with Ada.Text_IO; use Ada.Text_IO;
 
procedure Read_And_Write_File_Line_By_Line is
   Input, Output : File_Type;
begin
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");
   Create (File => Output,
           Mode => Out_File,
           Name => "output.txt");
   loop
      declare
         Line : String := Get_Line (Input);
      begin
         
         Put_Line (Output, Line);
      end;
   end loop;
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then 
         Close (Input);
      end if;
      if Is_Open(Output) then 
         Close (Output);
      end if;
end Read_And_Write_File_Line_By_Line;
Task: File input_output

C: #include <stdio.h>

int main(int argc, char **argv) {
  FILE *in, *out;
  int c;

  in = fopen("input.txt", "r");
  if (!in) {
    fprintf(stderr, "Error opening input.txt for reading.\n");
    return 1;
  }

  out = fopen("output.txt", "w");
  if (!out) {
    fprintf(stderr, "Error opening output.txt for writing.\n");
    fclose(in);
    return 1;
  }

  while ((c = fgetc(in)) != EOF) {
    fputc(c, out);
  }

  fclose(out);
  fclose(in);
  return 0;
}
Task: File input_output



C#: using System;
using System.IO;

namespace FileIO
{
  class Program
  {
    static void Main()
    {
      String s = scope .();
      File.ReadAllText("input.txt", s);
      File.WriteAllText("output.txt", s);
    }
  }
}
Task: File input_output


C++: #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    string line;
    ifstream input ( "input.txt" );
    ofstream output ("output.txt");
    
    if (output.is_open()) {
        if (input.is_open()){
            while (getline (input,line)) {
                output << line << endl;
            }
            input.close(); 
        }
        else {
            cout << "input.txt cannot be opened!\n";
        }
        output.close(); 
    }
    else {
        cout << "output.txt cannot be written to!\n";
    }
    return 0;
}
Task: File input_output





Java: import java.io.*;

public class FileIODemo {
  public static void main(String[] args) {
    try {
      FileInputStream in = new FileInputStream("input.txt");
      FileOutputStream out = new FileOutputStream("ouput.txt");
      int c;
      while ((c = in.read()) != -1) {
        out.write(c);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e){
      e.printStackTrace();
    }
  }
}
Task: File input_output







Python: import shutil
shutil.copyfile('input.txt', 'output.txt')
Task: File input_output








VB: Sub WriteToFile(input As FolderItem, output As FolderItem)
  Dim tis As TextInputStream
  Dim tos As TextOutputStream
  tis = tis.Open(input)
  tos = tos.Create(output)
  While Not tis.EOF
    tos.WriteLine(tis.ReadLine)
  Wend
  tis.Close
  tos.Close
End Sub
Task: File input_output




Go: package main

import (
    "fmt"
    "io/ioutil"
)

func main() {
    b, err := ioutil.ReadFile("input.txt")
    if err != nil {
        fmt.Println(err)
        return
    }
    if err = ioutil.WriteFile("output.txt", b, 0666); err != nil {
        fmt.Println(err)
    }
}
Task: File input_output



C#: using System;
using System.IO;

namespace FileIO
{
  class Program
  {
    static void Main()
    {
      String s = scope .();
      File.ReadAllText("input.txt", s);
      File.WriteAllText("output.txt", s);
    }
  }
}








Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output


C++: #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    string line;
    ifstream input ( "input.txt" );
    ofstream output ("output.txt");
    
    if (output.is_open()) {
        if (input.is_open()){
            while (getline (input,line)) {
                output << line << endl;
            }
            input.close(); 
        }
        else {
            cout << "input.txt cannot be opened!\n";
        }
        output.close(); 
    }
    else {
        cout << "output.txt cannot be written to!\n";
    }
    return 0;
}









Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output

C: #include <stdio.h>

int main(int argc, char **argv) {
  FILE *in, *out;
  int c;

  in = fopen("input.txt", "r");
  if (!in) {
    fprintf(stderr, "Error opening input.txt for reading.\n");
    return 1;
  }

  out = fopen("output.txt", "w");
  if (!out) {
    fprintf(stderr, "Error opening output.txt for writing.\n");
    fclose(in);
    return 1;
  }

  while ((c = fgetc(in)) != EOF) {
    fputc(c, out);
  }

  fclose(out);
  fclose(in);
  return 0;
}










Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output





Java: import java.io.*;

public class FileIODemo {
  public static void main(String[] args) {
    try {
      FileInputStream in = new FileInputStream("input.txt");
      FileOutputStream out = new FileOutputStream("ouput.txt");
      int c;
      while ((c = in.read()) != -1) {
        out.write(c);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e){
      e.printStackTrace();
    }
  }
}






Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output







Python: import shutil
shutil.copyfile('input.txt', 'output.txt')




Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output








VB: Sub WriteToFile(input As FolderItem, output As FolderItem)
  Dim tis As TextInputStream
  Dim tos As TextOutputStream
  tis = tis.Open(input)
  tos = tos.Create(output)
  While Not tis.EOF
    tos.WriteLine(tis.ReadLine)
  Wend
  tis.Close
  tos.Close
End Sub



Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output






PHP: <?php

if (!$in = fopen('input.txt', 'r')) {
    die('Could not open input file.');
}

if (!$out = fopen('output.txt', 'w')) {
    die('Could not open output file.');
}

while (!feof($in)) {
    $data = fread($in, 512);
    fwrite($out, $data);
}

fclose($out);
fclose($in);
?>





Fortran: program FileIO

  integer, parameter :: out = 123, in = 124
  integer :: err
  character :: c

  open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
  if (err == 0) then
     open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
     if (err == 0) then
        err = 0
        do while (err == 0)
           read(unit=in, iostat=err) c
           if (err == 0) write(out) c
        end do
        close(in)
     end if
     close(out)
  end if

end program FileIO
Task: File input_output

C: #include <stdio.h>

int main(int argc, char **argv) {
  FILE *in, *out;
  int c;

  in = fopen("input.txt", "r");
  if (!in) {
    fprintf(stderr, "Error opening input.txt for reading.\n");
    return 1;
  }

  out = fopen("output.txt", "w");
  if (!out) {
    fprintf(stderr, "Error opening output.txt for writing.\n");
    fclose(in);
    return 1;
  }

  while ((c = fgetc(in)) != EOF) {
    fputc(c, out);
  }

  fclose(out);
  fclose(in);
  return 0;
}









COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.
Task: File input_output



C#: using System;
using System.IO;

namespace FileIO
{
  class Program
  {
    static void Main()
    {
      String s = scope .();
      File.ReadAllText("input.txt", s);
      File.WriteAllText("output.txt", s);
    }
  }
}







COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.
Task: File input_output


C++: #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    string line;
    ifstream input ( "input.txt" );
    ofstream output ("output.txt");
    
    if (output.is_open()) {
        if (input.is_open()){
            while (getline (input,line)) {
                output << line << endl;
            }
            input.close(); 
        }
        else {
            cout << "input.txt cannot be opened!\n";
        }
        output.close(); 
    }
    else {
        cout << "output.txt cannot be written to!\n";
    }
    return 0;
}








COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.
Task: File input_output





Java: import java.io.*;

public class FileIODemo {
  public static void main(String[] args) {
    try {
      FileInputStream in = new FileInputStream("input.txt");
      FileOutputStream out = new FileOutputStream("ouput.txt");
      int c;
      while ((c = in.read()) != -1) {
        out.write(c);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e){
      e.printStackTrace();
    }
  }
}





COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.
Task: File input_output







Python: import shutil
shutil.copyfile('input.txt', 'output.txt')



COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.
Task: File input_output








VB: Sub WriteToFile(input As FolderItem, output As FolderItem)
  Dim tis As TextInputStream
  Dim tos As TextOutputStream
  tis = tis.Open(input)
  tos = tos.Create(output)
  While Not tis.EOF
    tos.WriteLine(tis.ReadLine)
  Wend
  tis.Close
  tos.Close
End Sub


COBOL:        identification division.
       program-id. copyfile.
       environment division.
       input-output section.
       file-control.
           select input-file assign to "input.txt"
               organization sequential
           .
           select output-file assign to "output.txt"
               organization sequential
           .
       data division.
       file section.
       fd input-file.
       1 input-record pic x(80).
       fd output-file.
       1 output-record pic x(80).
       working-storage section.
       1 end-of-file-flag pic 9 value 0.
         88 eof value 1.
       1 text-line pic x(80).
       procedure division.
       begin.
           open input input-file
               output output-file
           perform read-input
           perform until eof
               write output-record from text-line
               perform read-input
           end-perform
           close input-file output-file
           stop run
           .
       read-input.
           read input-file into text-line
           at end
               set eof to true
           end-read
           .
       end program copyfile.