try { String filename= "MyFile.txt"; FileWriter fw = new FileWriter(filename,true); //the true will append the new data fw.write("add a line\n");//appends the string to the file fw.close(); } catch(IOException ioe) { System.err.println("IOException: " + ioe.getMessage()); }
URL url = new URL("http://www.example.com/resource"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod("PUT"); OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream()); out.write("Resource content"); out.close(); httpCon.getInputStream();
File myFoo = new File("foo.log"); FileWriter fooWriter = new FileWriter(myFoo, false); // true to append // false to overwrite. fooWriter.write("New Contents\n"); fooWriter.close();
try { File myFile = new File("/sdcard/mysdfile.txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD 'mysdfile.txt'", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); }
private String writeFile(String data) throws IOException { File file = File.createTempFile("lombok-processor-report-", ".txt"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file)); writer.write(data); writer.close(); return "Report written to '" + file.getCanonicalPath() + "'\n"; }
String urlParameters = "param1=a¶m2=b¶m3=c"; URL url = new URL("http://example.com/index.php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(urlParameters); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } writer.close(); reader.close();
OutputStreamWriter outStreamWriter = new OutputStreamWriter(urlConnection.getOutputStream()); outStreamWriter.write(loginData); outStreamWriter.close(); File file = new File(filePath); cursor.close(); return file; OutputStreamWriter outStreamWriter = new OutputStreamWriter(connection.getOutputStream()); outStreamWriter.write(atomData); outStreamWriter.close();
File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MySharedPreferences"); FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); fw.close();
conn.setDoOutput(true); conn.setConnectTimeout(1000 * 5); wr = new OutputStreamWriter(conn.getOutputStream()); wr.flush(); wr.close(); } catch (IOException e) { LOG.error("close error", e);
public static byte[] toCompressedJsonConf(Map<String, Object> topoConf) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(bos)); JSONValue.writeJSONString(topoConf, out); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
PrintWriter out = null; try { fw = new FileWriter("myfile.txt", true); bw = new BufferedWriter(fw); out = new PrintWriter(bw); fw.close(); } catch (IOException e) {
/** * base model 覆盖写入 */ protected void writeToFile(TableMeta tableMeta) throws IOException { File dir = new File(baseModelOutputDir); if (!dir.exists()) { dir.mkdirs(); } String target = baseModelOutputDir + File.separator + tableMeta.baseModelName + ".java"; OutputStreamWriter osw = null; try { osw = new OutputStreamWriter(new FileOutputStream(target), "UTF-8"); osw.write(tableMeta.baseModelContent); } finally { if (osw != null) { osw.close(); } } }
// get external storage file reference FileWriter writer = new FileWriter(getExternalStorageDirectory()); // Writes the content to the file writer.write("This\n is\n an\n example\n"); writer.flush(); writer.close();
public static void writeFile(String filePathAndName, String fileContent) { try { OutputStream outstream = new FileOutputStream(filePathAndName); OutputStreamWriter out = new OutputStreamWriter(outstream); out.write(fileContent); out.close(); } catch (java.io.IOException e) { e.printStackTrace(); } }
URL url = new URL(urlString); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty ("Authorization", encodedCredentials); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(data); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } writer.close(); reader.close();
osw = new OutputStreamWriter(connection.getOutputStream()); boolean isFirst = true; for (String key : content.keySet()) { osw.write(URLEncoder.encode(value, encodeCharset)); osw.flush(); osw.close(); } catch (IOException e) { } finally { if (osw != null) { try { osw.close(); } catch (Throwable e) {}
private void writeToFile(String data,Context context) { try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("config.txt", Context.MODE_PRIVATE)); outputStreamWriter.write(data); outputStreamWriter.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } }
FileWriter f0 = new FileWriter("output.txt"); String newLine = System.getProperty("line.separator"); for(i=0;i<10;i++) { f0.write("Result "+ i +" : "+ ans + newLine); } f0.close();
public static byte[] toCompressedJsonConf(Map<String, Object> stormConf) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(bos)); JSONValue.writeJSONString(stormConf, out); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }