java io work

This commit is contained in:
eugenp 2014-10-01 20:30:17 +03:00
parent 3fd347537c
commit 2a5d5481fc
1 changed files with 3 additions and 2 deletions

View File

@ -52,15 +52,16 @@ public class JavaWriteToFileTest {
} }
@Test @Test
public void whenWriteFormattedStringUsingPrintWriter_thenOutputShouldBeFormatted() throws IOException { public void givenWritingStringToFile_whenUsingPrintWriter_thenCorrect() throws IOException {
final FileWriter fileWriter = new FileWriter(fileName); final FileWriter fileWriter = new FileWriter(fileName);
final PrintWriter printWriter = new PrintWriter(fileWriter); final PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.print("Some String");
printWriter.printf("Product name is %s and its price is %d $", "iPhone", 1000); printWriter.printf("Product name is %s and its price is %d $", "iPhone", 1000);
printWriter.close(); printWriter.close();
} }
@Test @Test
public void whenWriteStringUsingFileOutputStream_thenCorrect() throws IOException { public void givenWritingStringToFile_whenUsingFileOutputStream_thenCorrect() throws IOException {
final String str = "Hello"; final String str = "Hello";
final FileOutputStream outputStream = new FileOutputStream(fileName3); final FileOutputStream outputStream = new FileOutputStream(fileName3);
final byte[] strToBytes = str.getBytes(); final byte[] strToBytes = str.getBytes();