本文整理了Java中java.io.PrintWriter.println()
方法的一些代码示例,展示了PrintWriter.println()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintWriter.println()
方法的具体详情如下:
包路径:java.io.PrintWriter
类名称:PrintWriter
方法名:println
[英]Prints a newline. Flushes this writer if the autoFlush flag is set to true.
[中]打印换行符。如果自动刷新标志设置为true,则刷新此写入程序。
代码示例来源: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: apache/incubator-dubbo
void println() {
if (!_isNewline) {
_dbg.println();
_dbg.flush();
}
_isNewline = true;
_column = 0;
}
代码示例来源:origin: stackoverflow.com
try(FileWriter fw = new FileWriter("outfilename", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw))
{
out.println("the text");
//more code
out.println("more text");
//more code
} catch (IOException e) {
//exception handling left as an exercise for the reader
}
代码示例来源:origin: apache/incubator-dubbo
/**
* write lines.
*
* @param os output stream.
* @param lines lines.
* @throws IOException
*/
public static void writeLines(OutputStream os, String[] lines) throws IOException {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(os));
try {
for (String line : lines) {
writer.println(line);
}
writer.flush();
} finally {
writer.close();
}
}
代码示例来源:origin: stackoverflow.com
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter("writePath", true)));
out.println("the text");
}catch (IOException e) {
System.err.println(e);
}finally{
if(out != null){
out.close();
}
}
代码示例来源:origin: marytts/marytts
private static void saveIndex() {
assert remote2local != null;
File downloadDir = new File(System.getProperty("mary.downloadDir", "."));
File licenseIndexFile = new File(downloadDir, "license-index.txt");
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(licenseIndexFile), "UTF-8"))) {
for (URL remote : remote2local.keySet()) {
pw.println(remote2local.get(remote) + "|" + remote.toString());
}
} catch (IOException e) {
System.err.println("Problem updating the index file " + licenseIndexFile.getAbsolutePath());
e.printStackTrace();
}
}
代码示例来源:origin: Tencent/tinker
String outputFullFilename = new File(outputDirectory).getAbsolutePath() + Constant.Symbol.SLASH_LEFT + (packageName.replace(Constant.Symbol.DOT, Constant.Symbol.SLASH_LEFT) + Constant.Symbol.SLASH_LEFT + "R" + Constant.Symbol.DOT + Constant.File.JAVA);
FileUtil.createFile(outputFullFilename);
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileOutputStream(outputFullFilename));
writer.format("package %s;\n\n", packageName);
writer.println("public final class R {\n");
for (RType rType : rTypeResourceMap.keySet()) {
writer.println(" }\n");
writer.println("}");
} catch (Exception e) {
throw new AaptUtilException(e);
代码示例来源:origin: stanfordnlp/CoreNLP
private static void reportError(String yytext) {
try {
PrintWriter p = new PrintWriter(new OutputStreamWriter(System.err,
"utf-8"), true);
p.println("chtbl.flex tokenization error: \"" + yytext + "\"");
if (yytext.length() >= 1) {
p.println("First character is: " + yytext.charAt(0));
if (yytext.length() >= 2) {
p.println("Second character is: " + yytext.charAt(1));
}
}
} catch (UnsupportedEncodingException e) {
System.err.println("chtbl.flex tokenization and encoding present error");
}
}
代码示例来源: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: plantuml/plantuml
private static void exportDiagramErrorText(OutputStream os, Throwable exception, List<String> strings) {
final PrintWriter pw = new PrintWriter(os);
exception.printStackTrace(pw);
pw.println();
pw.println();
for (String s : strings) {
s = s.replaceAll("\\</?\\w+?\\>", "");
pw.println(s);
}
pw.flush();
}
代码示例来源:origin: Netflix/eureka
protected void sendOkResponseWithContent(Request request, HttpServletResponse response, Applications apps)
throws IOException {
String content = XmlXStream.getInstance().toXML(apps);
response.setContentType("application/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(content);
response.getWriter().flush();
request.setHandled(true);
System.out.println("Eureka port: " + port + ". " + System.currentTimeMillis() +
". Eureka resource mock, sent response for request path: " + request.getPathInfo() +
", apps count: " + apps.getRegisteredApplications().size());
}
代码示例来源:origin: stackoverflow.com
public class ConsoleDemo {
public static void main(String[] args) {
String[] data = { "\u250C\u2500\u2500\u2500\u2500\u2500\u2510",
"\u2502Hello\u2502",
"\u2514\u2500\u2500\u2500\u2500\u2500\u2518" };
for (String s : data) {
System.out.println(s);
}
for (String s : data) {
System.console().writer().println(s);
}
}
}
代码示例来源:origin: redisson/redisson
public void print(PrintWriter out) {
out.print("Integer ");
out.println(value);
}
}
代码示例来源:origin: gocd/gocd
public void typeInputToConsole(List<String> inputs) {
for (String input : inputs) {
processInputStream.println(input);
processInputStream.flush();
}
processInputStream.close();
}
代码示例来源:origin: apache/incubator-dubbo
/**
* write lines.
*
* @param os output stream.
* @param lines lines.
* @throws IOException
*/
public static void writeLines(OutputStream os, String[] lines) throws IOException {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(os));
try {
for (String line : lines) {
writer.println(line);
}
writer.flush();
} finally {
writer.close();
}
}
代码示例来源:origin: twitter/distributedlog
void dumpLedgers(Set<Long> ledgers, File targetFile) throws Exception {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(targetFile), UTF_8.name()));
try {
for (Long ledger : ledgers) {
pw.println(ledger);
}
} finally {
pw.close();
}
System.out.println("Dump " + ledgers.size() + " ledgers to file : " + targetFile);
}
代码示例来源:origin: marytts/marytts
private static void saveIndex() {
assert remote2local != null;
File downloadDir = new File(System.getProperty("mary.downloadDir", "."));
File licenseIndexFile = new File(downloadDir, "license-index.txt");
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(licenseIndexFile), "UTF-8"))) {
for (URL remote : remote2local.keySet()) {
pw.println(remote2local.get(remote) + "|" + remote.toString());
}
} catch (IOException e) {
System.err.println("Problem updating the index file " + licenseIndexFile.getAbsolutePath());
e.printStackTrace();
}
}
代码示例来源:origin: apache/incubator-pinot
private void persistIndexMap(IndexEntry entry)
throws IOException {
File mapFile = new File(segmentDirectory, INDEX_MAP_FILE);
try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(mapFile, true)))) {
String startKey = getKey(entry.key.name, entry.key.type.getIndexName(), true);
StringBuilder sb = new StringBuilder();
sb.append(startKey).append(" = ").append(entry.startOffset);
writer.println(sb.toString());
String endKey = getKey(entry.key.name, entry.key.type.getIndexName(), false);
sb = new StringBuilder();
sb.append(endKey).append(" = ").append(entry.size);
writer.println(sb.toString());
}
}
代码示例来源:origin: stackoverflow.com
try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("writePath", true)))) {
out.println("the text");
}catch (IOException e) {
System.err.println(e);
}
代码示例来源:origin: spotbugs/spotbugs
public static void main(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();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!