stream to file code example

Example 1: C# save pdf stream to file

using (var fileStream = File.Create("C:\\Path\\To\\File"))
{
    myStream.Seek(0, SeekOrigin.Begin);
    myStream.CopyTo(fileStream);
}

Example 2: java stream write to file

@Test
public void givenWritingStringToFile_whenUsingPrintWriter_thenCorrect() 
  throws IOException {
    FileWriter fileWriter = new FileWriter(fileName);
    PrintWriter printWriter = new PrintWriter(fileWriter);
    printWriter.print("Some String");
    printWriter.printf("Product name is %s and its price is %d $", "iPhone", 1000);
    printWriter.close();
}