Tabnine Logo
java.io
Code IndexAdd Tabnine to your IDE (free)

How to use java.io

Best Java code snippets using java.io (Showing top 20 results out of 240,264)

origin: stackoverflow.com

 StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString(); // stack trace as a string
origin: stackoverflow.com

 for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
  System.out.println(header.getKey() + "=" + header.getValue());
}
origin: stackoverflow.com

 try {
  BufferedReader br = new BufferedReader(new FileReader(inputFile));
  ...
  ...
} catch (Exception e) {
  e.printStacktrace();
}
origin: spring-projects/spring-framework

public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(baos);
  oos.writeObject(o);
  oos.flush();
  baos.flush();
  byte[] bytes = baos.toByteArray();
  ByteArrayInputStream is = new ByteArrayInputStream(bytes);
  ObjectInputStream ois = new ObjectInputStream(is);
  Object o2 = ois.readObject();
  return o2;
}
origin: iluwatar/java-design-patterns

/**
 * @return True, if the file given exists, false otherwise.
 */
public boolean fileExists() {
 return new File(this.fileName).exists();
}
origin: google/guava

 @GwtIncompatible // serialization
 private static Object reserialize(Object object) throws Exception {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  new ObjectOutputStream(bytes).writeObject(object);
  return new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject();
 }
}
origin: square/okhttp

@Override public void delete(File file) throws IOException {
 // If delete() fails, make sure it's because the file didn't exist!
 if (!file.delete() && file.exists()) {
  throw new IOException("failed to delete " + file);
 }
}
origin: stackoverflow.com

 public class DownloadTask extends GroundyTask {    
  public static final String PARAM_URL = "com.groundy.sample.param.url";

  @Override
  protected boolean doInBackground() {
    try {
      String url = getParameters().getString(PARAM_URL);
      File dest = new File(getContext().getFilesDir(), new File(url).getName());
      DownloadUtils.downloadFile(getContext(), url, dest, DownloadUtils.getDownloadListenerForTask(this));
      return true;
    } catch (Exception pokemon) {
      return false;
    }
  }
}
origin: stackoverflow.com

 try(BufferedReader br = new BufferedReader(new FileReader(file))) {
  for(String line; (line = br.readLine()) != null; ) {
    // process the line.
  }
  // line is not visible here.
}
origin: google/guava

@Override
public synchronized void reset() throws IOException {
 if (!in.markSupported()) {
  throw new IOException("Mark not supported");
 }
 if (mark == -1) {
  throw new IOException("Mark not set");
 }
 in.reset();
 left = mark;
}
origin: google/guava

@Override
public long size() throws IOException {
 if (!file.isFile()) {
  throw new FileNotFoundException(file.toString());
 }
 return file.length();
}
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: stackoverflow.com

 StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
origin: iluwatar/java-design-patterns

 @Override
 protected void printThisBefore() {
  System.out.print(c);
 }
}
origin: stackoverflow.com

 public class Test {
 public static void main(String[] args) {
  outerloop:
  for (int i=0; i < 5; i++) {
   for (int j=0; j < 5; j++) {
    if (i * j > 6) {
     System.out.println("Breaking");
     break outerloop;
    }
    System.out.println(i + " " + j);
   }
  }
  System.out.println("Done");
 }
}
origin: stackoverflow.com

 try (BufferedReader br = new BufferedReader(new FileReader(file))) {
  String line;
  while ((line = br.readLine()) != null) {
    // process the line.
  }
}
origin: google/guava

 @Override
 public synchronized void reset() throws IOException {
  if (!in.markSupported()) {
   throw new IOException("Mark not supported");
  }
  if (mark == -1) {
   throw new IOException("Mark not set");
  }

  in.reset();
  count = mark;
 }
}
origin: iluwatar/java-design-patterns

 @Override
 protected void printThisAfter() {
  System.out.print(".");
 }
}
origin: stackoverflow.com

 Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet())
{
  System.out.println(entry.getKey() + "/" + entry.getValue());
}
origin: stackoverflow.com

 import java.util.TimeZone;

public class Test {
  public static void main(String[] args) throws Exception {
    long startOf1900Utc = -2208988800000L;
    for (String id : TimeZone.getAvailableIDs()) {
      TimeZone zone = TimeZone.getTimeZone(id);
      if (zone.getRawOffset() != zone.getOffset(startOf1900Utc - 1)) {
        System.out.println(id);
      }
    }
  }
}
java.io

Most used classes

  • File
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • PrintStream
    A PrintStream adds functionality to another output stream, namely the ability to print representatio
  • IOException
  • InputStream
  • FileInputStream
    A FileInputStream obtains input bytes from a file in a file system. What files are available depends
  • ByteArrayOutputStream,
  • BufferedReader,
  • FileOutputStream,
  • ByteArrayInputStream,
  • OutputStream,
  • PrintWriter,
  • StringWriter,
  • StringReader,
  • OutputStreamWriter,
  • BufferedInputStream,
  • Writer,
  • ObjectInputStream,
  • FileNotFoundException,
  • FileReader
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