Here you can find the source of getPrintWriter(File file)
Parameter | Description |
---|---|
file | -- the output file |
Parameter | Description |
---|---|
IOException | an exception |
public static PrintWriter getPrintWriter(File file) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.zip.GZIPOutputStream; public class Main { /**// w w w . ja v a 2s . c o m * Init. a writer for the given file object. * In the case of .gz file name ending a GZIP compressed writer is returned. * @param file -- the output file * @return PrintWriter for file * @throws IOException */ public static PrintWriter getPrintWriter(File file) throws IOException { //check for compressing if (file.getName().endsWith(".gz")) { return new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))); } return new PrintWriter(file); } }