public static void print(String[][] cols) throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename)); for (String[] col : cols) { if (col.length >= 2) { out.write(col[0] + "\t" + col[1] + "\n"); } else { out.write("\n"); } } out.flush(); out.close(); }
PrintWriter out = null; try { fw = new FileWriter("myfile.txt", true); bw = new BufferedWriter(fw); out = new PrintWriter(bw); out.println("the text"); bw.close(); } catch (IOException e) {
private static boolean writeValue(Socket client, String value) { boolean result; BufferedWriter out = null; try { OutputStream clientStream = client.getOutputStream(); out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); out.write(value); out.write("\n"); out.flush(); result = true; } catch (Exception e) { result = false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { result = false; } } } return result; }
DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8")); writer.write(content); writer.close(); wr.close();
/** * 将字符串写到文件 * @param path * @param str * @throws IOException */ public static void write(String path, String str) throws IOException { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( path), "utf8")); out.append(str); out.close(); } public static void write(String path, Serializable o) {
public static String toStd(DexClassNode expected) throws IOException { StringWriter stringWriter = new StringWriter(); BufferedWriter bufferedWriter = new BufferedWriter(stringWriter); BaksmaliDumpOut out = new BaksmaliDumpOut(bufferedWriter); final BaksmaliDumper bs = new BaksmaliDumper(true, false); bs.baksmaliClass(expected, out); bufferedWriter.close(); return stringWriter.toString(); } }
public static void writeToFile(File file, Set<String> content) throws IOException { FileWriter fw = new FileWriter(file, false); BufferedWriter bw = new BufferedWriter(fw); Iterator<String> iter = content.iterator(); while (iter.hasNext()) { bw.write(iter.next()); bw.write(System.lineSeparator()); } bw.close(); }
public void biList2File(String output) throws IOException { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); for (ArrayList<String> list : clusterResult) { for (String s : list) { bw.write(s + " "); } bw.write("\n"); } bw.close(); }
public static void main(String[] args) throws Exception { String nodeValue = "i am mostafa"; // you want to output to file // BufferedWriter writer = new BufferedWriter(new FileWriter(file3, true)); // but let's print to console while debugging BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); String[] words = nodeValue.split(" "); for (String word: words) { writer.write(word); writer.newLine(); } writer.close(); }
public void produceTrees(String filename, int numTrees) { try { FileWriter fout = new FileWriter(filename); BufferedWriter bout = new BufferedWriter(fout); PrintWriter pout = new PrintWriter(bout); produceTrees(pout, numTrees); pout.close(); bout.close(); fout.close(); } catch (IOException e) { throw new RuntimeIOException(e); } }
public void translateFile(String input, String output) { try { FileInputStream fis = new FileInputStream(input); InputStreamReader isr = new InputStreamReader(fis, "utf-8"); BufferedReader br = new BufferedReader(isr); FileOutputStream fos = new FileOutputStream(output); OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8"); BufferedWriter bw = new BufferedWriter(osw); translateLines(br, bw); bw.close(); osw.close(); fos.close(); br.close(); isr.close(); fis.close(); } catch (IOException e) { throw new RuntimeIOException(e); } }
public void testNewWriter() throws IOException { File temp = createTempFile(); try { Files.newWriter(temp, null); fail("expected exception"); } catch (NullPointerException expected) { } try { Files.newWriter(null, Charsets.UTF_8); fail("expected exception"); } catch (NullPointerException expected) { } BufferedWriter w = Files.newWriter(temp, Charsets.UTF_8); try { w.write(I18N); } finally { w.close(); } File i18nFile = getTestFile("i18n.txt"); assertTrue(Files.equal(i18nFile, temp)); }
static void writeFile(File outputFile, String str) throws IOException { BufferedWriter w = new BufferedWriter(new FileWriter(outputFile)); w.write(str); w.close(); }
@Override public boolean saveTxtTo(String path) { try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path))); bw.write(toString()); bw.close(); } catch (Exception e) { logger.warning("在保存转移矩阵词典到" + path + "时发生异常" + e); return false; } return true; } }
URL url = new URL("http://yoururl.com"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); Uri.Builder builder = new Uri.Builder() .appendQueryParameter("firstParam", paramValue1) .appendQueryParameter("secondParam", paramValue2) .appendQueryParameter("thirdParam", paramValue3); String query = builder.build().getEncodedQuery(); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); writer.write(query); writer.flush(); writer.close(); os.close(); conn.connect();
static public void writeColumnOutput(String outFile, boolean batchProcessSents, Map<String, Class<? extends TypesafeMap.Key<String>>> answerclasses) throws IOException, ClassNotFoundException { BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); ConstantsAndVariables.DataSentsIterator sentsIter = new ConstantsAndVariables.DataSentsIterator(batchProcessSents); while(sentsIter.hasNext()){ Pair<Map<String, DataInstance>, File> sentsf = sentsIter.next(); writeColumnOutputSents(sentsf.first(), writer, answerclasses); } writer.close(); }
public static void dumpMatrix(String filename, SimpleMatrix matrix) throws IOException { String matrixString = matrix.toString(); int newLine = matrixString.indexOf("\n"); if (newLine >= 0) { matrixString = matrixString.substring(newLine + 1); } FileWriter fout = new FileWriter(filename); BufferedWriter bout = new BufferedWriter(fout); bout.write(matrixString); bout.close(); fout.close(); }
private boolean listWindows(Socket client) { boolean result = true; BufferedWriter out = null; try { mWindowsLock.readLock().lock(); OutputStream clientStream = client.getOutputStream(); out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); for (Entry<View, String> entry : mWindows.entrySet()) { out.write(Integer.toHexString(System.identityHashCode(entry.getKey()))); out.write(' '); out.append(entry.getValue()); out.write('\n'); } out.write("DONE.\n"); out.flush(); } catch (Exception e) { result = false; } finally { mWindowsLock.readLock().unlock(); if (out != null) { try { out.close(); } catch (IOException e) { result = false; } } } return result; }
BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); writer.write(getPostDataString(postDataParams)); writer.close(); os.close(); int responseCode=conn.getResponseCode();