Tabnine Logo
PrintWriter
Code IndexAdd Tabnine to your IDE (free)

How to use
PrintWriter
in
java.io

Best Java code snippets using java.io.PrintWriter (Showing top 20 results out of 73,440)

Refine searchRefine arrow

  • StringWriter
  • HttpServletResponse
  • HttpServletRequest
  • OutputStreamWriter
  • BufferedReader
  • InputStreamReader
  • Socket
  • FileOutputStream
  • BufferedWriter
  • FileReader
canonical example by Tabnine

public void writeToFile(File dest, String content, boolean append) throws IOException {
  // append - true for writing to the end of the file rather to the beginning
  try (PrintWriter writer = new PrintWriter(new FileWriter(dest, append))) {
    writer.print(content);
  }
}
origin: stanfordnlp/CoreNLP

private Session(Socket socket) throws IOException {
 client = socket;
 in = new BufferedReader(new InputStreamReader(client.getInputStream(), charset));
 out = new PrintWriter(new OutputStreamWriter(client.getOutputStream(), charset));
 start();
}
origin: jenkinsci/jenkins

/**
 * Reads the entire contents and returns it.
 */
public String read() throws IOException {
  StringWriter out = new StringWriter();
  PrintWriter w = new PrintWriter(out);
  try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(file), StandardCharsets.UTF_8)) {
    String line;
    while ((line = in.readLine()) != null)
      w.println(line);
  } catch (Exception e) {
    throw new IOException("Failed to fully read " + file, e);
  }
  return out.toString();
}
origin: stackoverflow.com

String line = "שלום, hello, привет";
 OutputStream os = new FileOutputStream("c:/temp/j.csv");
 os.write(239);
 os.write(187);
 os.write(191);
 PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
 w.print(line);
 w.flush();
 w.close();
origin: stackoverflow.com

 try{
  PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
  writer.println("The first line");
  writer.println("The second line");
  writer.close();
} catch (IOException e) {
  // do something
}
origin: spring-projects/spring-framework

@Override
public void write(char[] buf, int off, int len) {
  super.write(buf, off, len);
  super.flush();
  setCommittedIfBufferSizeExceeded();
}
origin: stackoverflow.com

 try {
  PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt", true)));
  out.println("the text");
  out.close();
} catch (IOException e) {
  //exception handling left as an exercise for the reader
}
origin: spotbugs/spotbugs

public static void test(String[] args) throws IOException {
  InputStream is = new FileInputStream("test.txt");
  OutputStream os = new FileOutputStream("/tmp/test.txt");
  try {
    BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
    String line;
    while ((line = r.readLine()) != null) {
      w.println(line);
    }
  } finally {
    is.close();
  }
}
origin: apache/incubator-pinot

public static void main(String[] args)
  throws Exception {
 if (args.length != 3) {
  LOGGER.error("Incorrect arguments");
  LOGGER.info("Usage: <exec> <UntarredSegmentDir> <QueryFile> <outputFile>");
  System.exit(1);
 }
 String segDir = args[0];
 String queryFile = args[1];
 String outputFile = args[2];
 String query;
 ScanBasedQueryProcessor scanBasedQueryProcessor = new ScanBasedQueryProcessor(segDir);
 BufferedReader bufferedReader = new BufferedReader(new FileReader(queryFile));
 PrintWriter printWriter = new PrintWriter(outputFile);
 while ((query = bufferedReader.readLine()) != null) {
  QueryResponse queryResponse = scanBasedQueryProcessor.processQuery(query);
  printResult(queryResponse);
  printWriter.println("Query: " + query);
  printWriter.println("Result: " + JsonUtils.objectToString(queryResponse));
 }
 bufferedReader.close();
 printWriter.close();
}
origin: stanfordnlp/CoreNLP

BufferedReader stdIn = new BufferedReader(
    new InputStreamReader(System.in, charset));
log.info("Input some text and press RETURN to POS tag it, or just RETURN to finish.");
for (String userInput; (userInput = stdIn.readLine()) != null && ! userInput.matches("\\n?"); ) {
 try {
  Socket socket = new Socket(host, port);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), charset), true);
  BufferedReader in = new BufferedReader(new InputStreamReader(
      socket.getInputStream(), charset));
  PrintWriter stdOut = new PrintWriter(new OutputStreamWriter(System.out, charset), true);
  out.println(userInput);
  stdOut.println(in.readLine());
  while (in.ready()) {
   stdOut.println(in.readLine());
  in.close();
origin: DeemOpen/zkui

  public String executeCmd(String cmd, String zkServer, String zkPort) throws IOException {
    StringBuilder sb;
    try (Socket s = new Socket(zkServer, Integer.parseInt(zkPort)); PrintWriter out = new PrintWriter(s.getOutputStream(), true); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()))) {
      out.println(cmd);
      String line = reader.readLine();
      sb = new StringBuilder();
      while (line != null) {
        sb.append(line);
        sb.append("<br/>");
        line = reader.readLine();
      }
    }
    return sb.toString();
  }
}
origin: stanfordnlp/CoreNLP

String currentInfile = "";
try {
 outfile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName),"UTF-8")));
  infile = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(path),"UTF-8")));
  currentInfile = path.getPath();
   outfile.println(SentenceUtils.listToString(sent));
} finally {
 if(outfile != null)
  outfile.close();
origin: spotbugs/spotbugs

@Override
@ExpectWarning("PT_RELATIVE_PATH_TRAVERSAL")
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.setContentType("text/plain");
  PrintWriter out = response.getWriter();
  String path = request.getParameter("path");
  BufferedReader r = new BufferedReader(new FileReader("data/" + path));
  while (true) {
    String txt = r.readLine();
    if (txt == null)
      break;
    out.println(txt);
  }
  out.close();
  r.close();
}
origin: jmxtrans/jmxtrans

private void processRequests(ServerSocket server) throws IOException {
  Socket socket = server.accept();
  connectionsAccepted.incrementAndGet();
  try (
      BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), UTF_8));
      PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8))
  ){
    synchronized (startSynchro) {
      startSynchro.notifyAll();
    }
    String line;
    while ((line = in.readLine()) != null) {
      receivedMessages.add(line);
      out.print(line);
    }
  }
}
origin: stanfordnlp/CoreNLP

private static void resolveDummyTags(File treeFile,
  TwoDimensionalCounter<String, String> pretermLabel,
  TwoDimensionalCounter<String, String> unigramTagger) {
 try {
  BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), "UTF-8"));
  TreeReaderFactory trf = new FrenchTreeReaderFactory();
  TreeReader tr = trf.newTreeReader(br);
  PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(treeFile + ".fixed")),false,"UTF-8"));
  int nTrees = 0;
  for(Tree t; (t = tr.readTree()) != null;nTrees++) {
   traverseAndFix(t, pretermLabel, unigramTagger);
   pw.println(t.toString());
  }
  pw.close();
  tr.close();
  System.out.println("Processed " +nTrees+ " trees");
 } catch (UnsupportedEncodingException e) {
  e.printStackTrace();
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 }
}
origin: stanfordnlp/CoreNLP

public static PrintWriter getPrintWriter(File textFile, String encoding) throws IOException {
 File f = textFile.getAbsoluteFile();
 if (encoding == null) {
  encoding = defaultEncoding;
 }
 return new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding)), true);
}
origin: stanfordnlp/CoreNLP

public static void main(String[] args) throws Exception {
 if (args.length != 2) {
  log.info("usage: java TaggerDemo2 modelFile fileToTag");
  return;
 }
 MaxentTagger tagger = new MaxentTagger(args[0]);
 TokenizerFactory<CoreLabel> ptbTokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(),
                   "untokenizable=noneKeep");
 BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "utf-8"));
 PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, "utf-8"));
 DocumentPreprocessor documentPreprocessor = new DocumentPreprocessor(r);
 documentPreprocessor.setTokenizerFactory(ptbTokenizerFactory);
 for (List<HasWord> sentence : documentPreprocessor) {
  List<TaggedWord> tSentence = tagger.tagSentence(sentence);
  pw.println(SentenceUtils.listToString(tSentence, false));
 }
 // print the adjectives in one more sentence. This shows how to get at words and tags in a tagged sentence.
 List<HasWord> sent = SentenceUtils.toWordList("The", "slimy", "slug", "crawled", "over", "the", "long", ",", "green", "grass", ".");
 List<TaggedWord> taggedSent = tagger.tagSentence(sent);
 for (TaggedWord tw : taggedSent) {
  if (tw.tag().startsWith("JJ")) {
   pw.println(tw.word());
  }
 }
 pw.close();
}
origin: stackoverflow.com

 StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString(); // stack trace as a string
origin: apache/incubator-dubbo

public static String toString(Throwable e) {
  StringWriter w = new StringWriter();
  PrintWriter p = new PrintWriter(w);
  p.print(e.getClass().getName() + ": ");
  if (e.getMessage() != null) {
    p.print(e.getMessage() + "\n");
  }
  p.println();
  try {
    e.printStackTrace(p);
    return w.toString();
  } finally {
    p.close();
  }
}
origin: apache/ignite

File dstFile = new File(testWorkDir, "mapred-site.xml");
try (BufferedReader in = new BufferedReader(new FileReader(srcFile));
   PrintWriter out = new PrintWriter(dstFile)) {
  String line;
  while ((line = in.readLine()) != null) {
    if (line.startsWith("</configuration>"))
      out.println(
        "    <property>\n" +
        "        <name>" + HadoopCommonUtils.JOB_COUNTER_WRITER_PROPERTY + "</name>\n" +
        "    </property>\n");
    out.println(line);
  out.flush();
java.ioPrintWriter

Javadoc

Wraps either an existing OutputStream or an existing Writerand provides convenience methods for printing common data types in a human readable format. No IOException is thrown by this class. Instead, callers should use #checkError() to see if a problem has occurred in this writer.

Most used methods

  • <init>
  • println
    Prints an array of characters and then terminates the line. This method behaves as though it invokes
  • flush
    Flushes the stream.
  • close
    Closes the stream and releases any system resources associated with it. Closing a previously closed
  • print
    Prints an array of characters. The characters are converted into bytes according to the platform's d
  • write
    Writes A Portion of an array of characters.
  • printf
    Prints a formatted string. The behavior of this method is the same as this writer's #format(Locale,
  • append
  • checkError
    Flushes the stream if it's not closed and checks its error state.
  • format
    Writes a string formatted by an intermediate Formatter to the target using the specified locale, for
  • setError
    Indicates that an error has occurred. This method will cause subsequent invocations of #checkError()
  • doWrite
  • setError,
  • doWrite,
  • clearError,
  • ensureOpen,
  • newLine,
  • toCharset

Popular in Java

  • Finding current android device location
  • findViewById (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onRequestPermissionsResult (Fragment)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • JComboBox (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now