Skip to content

Commit 20637ea

Browse files
Use a PrintWriter to make printf available. (GoogleCloudPlatform#2808)
Otherwise we have to call String.format. This also fixes a place where we weren't in fact calling String.format even though we were using the %n format specifier.
1 parent f835518 commit 20637ea

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

functions/concepts/file-system/src/main/java/functions/FileSystem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import com.google.cloud.functions.HttpFunction;
2222
import com.google.cloud.functions.HttpRequest;
2323
import com.google.cloud.functions.HttpResponse;
24-
import java.io.BufferedWriter;
2524
import java.io.File;
2625
import java.io.IOException;
26+
import java.io.PrintWriter;
2727

2828
public class FileSystem implements HttpFunction {
2929

@@ -33,10 +33,10 @@ public void service(HttpRequest request, HttpResponse response)
3333
throws IOException {
3434
File currentDirectory = new File(".");
3535
File[] files = currentDirectory.listFiles();
36-
BufferedWriter writer = response.getWriter();
37-
writer.write("Files: %n");
36+
PrintWriter writer = new PrintWriter(response.getWriter());
37+
writer.println("Files:");
3838
for (File f : files) {
39-
writer.write(String.format("\t%s%n", f.getName()));
39+
writer.printf("\t%s%n", f.getName());
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)