Does it make sense to always wrap an InputStream as BufferedInputStream, when I know whether the given InputStream is something other than buffered? For e.g:
InputStream is = API.getFromSomewhere()
if(!(is instanceof BufferedInputStream))
return new BufferedInputStream(is);
return is;
...
For example, I want to zip a file stored in /Users/me/Desktop/image.jpg
I made this method:
public static Boolean generateZipFile(ArrayList<String> sourcesFilenames, String destinationDir, String zipFilename){
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// VER SI HAY QUE CREAR EL ROOT PATH
...
Hello, i try to compile a java program but in the import section of the code fails:
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.*;
//import java.awt.image.*;
import java.awt.event.*;
//import java.awt.image.renderable.*;
import javax.swing.*;
import javax.swing.border.*;
//import javax.sw...
Before when I use file in my fileWritter it worked, but now since I'm using getResourceAsStream instead of file how can I make it work?
FileWriter fstream = new FileWriter(new File("filename"), true);
Now when I pass
InputStream is = getResourceAsStream("filename");
FileWriter fstream = new FileWriter(is, true);
I had to change i...
Trying to read a binary data file in the assets directory of android app:
void loadFile(InputStream filein){
log(filein.available()); // returns 11310099
int a = filein.read(); // returns -1 (i.e. EOF)
}
// Function was called using:
loadFile(context.getAssets().open("filename.dat"));
So if available() correctly returns that th...
What are the differences (if any) between the following two buffering approaches?
Reader r1 = new BufferedReader(new InputStreamReader(in, "UTF-8"), bufferSize);
Reader r2 = new InputStreamReader(new BufferedInputStream(in, bufferSize), "UTF-8");
...
I have a Java program that creates a number of xml file and then zips them up and saves them to the file system. Later in the program I want to put that same zip file into a blob column of my oracle database. Problem is I'm not sure how to do that. I don't need to read it or do anything with the data, just move it to the database for p...
i use follows code to get page content:
URL url=new URL("http://www.google.com.hk/intl/zh-CN/privacy.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
for(String line=reader.readLine();line!=null;line=reader.readLine()){
System.out.println(line);
}
reader.close();
pag...
i has a BufferedImage instance: (only a example)
BufferedImage image = ImageIO.read(new URL("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"));
now,i only know use
ImageIO.write(image,"jpg", file); //or ImageIO.write(image,"png", file);
to save this BufferedImage to a file, but this file is ZIPed,not equal original image...
I am trying to load a text file from the src package. I don't want to load it as an input stream. I would like to load it as an FileReader.
Looking at how netbeans loads icons, I tried using the code:
getClass().getResourcesAsStream("/getresources/test.txt");
However, I can't find any way to convert an inputstream into a filereader. ...
It's perfectly described here how to do it, the only problem: He doesnt know the function openFileOutput();
private void saveSettingsFile() {
String FILENAME = "settings";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); //openFileOutput underlined red
...
hi guys,
I'm using PDF-Renderer to view PDF files within my java application. It's working perfectly for normal PDF files.
However, i want the application to be able to display encrypted PDF files. The ecrypted file will be decrypted with CipherInputStream, but i do not want to save the decrypted data on disk. Am trying to figure a way...
I want to to detect whether a given program can perform malicious operations like forking , interprocess piping , input/output redirection, file handling etc.
Actually I am developing a program that checks java codes and do not want the coder to harm my code checker system in any way.
What are the packages I should look for in code to en...
The only way I know is to write a temp file, and read this file to create RandomAccessFile ,check it here
or use Use Unified I/O library (http://uio.imagero.com) here
Would this be the best way? Or can use temp file and the imageio library to implement it?
...
I am listening changes to a syslog file in Java. I use the accepted answer to process new entries to the file. However, I couldnt find an efficient solution for detecting rollover files. Syslog file might be rolledover daily or based on filesize.
What are the best practises for handling such a case?
...
Hi,
The good:
so, I have this binary data file (size - exactly 640631 bytes), and I'm trying to make Java read it.
I have two interchangeable classes implemented as layers for reading that data. One of them uses RandomAccessFile, which works great and all.
The bad:
Another one (the one this question is mostly about) tries to use Fil...
Hi, i'm not a java developer, but i need to write a small applet to upload file via ftp
(actually, i'm a web developer). Everything works fine, except for the way that feedback messages are displayed. Let me explain with an example:
if i wrote sometingh like that, inside a method (controlled by a click event)
//....
myJpanel.setText("C...