FileInputStream « API « Java I/O Q&A





1. Closing a Java FileInputStream    stackoverflow.com

Alright, I have been doing the following (variable names have been changed):


FileInputStream fis = null;
try
{
    fis = new FileInputStream(file);

    ... process ...

    ...

2. Most concise way to read the contents of a file/input stream in Java?    stackoverflow.com

What ist most concise way to read the contents of a file or input stream in Java? Do I always have to create a buffer, read (at most) line by line ...

3. Using Java's FileInputStream    stackoverflow.com

In java.io.FileInputStream, there is a method int read(Byte[] buffer,int offset,int numBytes); how we can use this function - is there any difference between this method and read(byte[] buffer)?

4. Howto cancel a delayed FileInputStream file-open    stackoverflow.com

Is there a way to cancel a long running file open operation? Long delays due anti-virus scans, mapped network drives etc.

new FileInputStream("a_file_that_the_antivirus_" + 
    "will_process_for_minutes_before_returning.jar")
// process the contents...
In ...

5. Java Gridgain application starts to fail after 1 day of stress testing    stackoverflow.com

So I have a an application which is running on top of gridgain and does so quite successfully for about 12-24 hours of stress testing before it starts to act funny. ...

6. FileInputStream negative skip    stackoverflow.com

I'm trying to find more about history of java.io.FileInputStream.skip(n) operation when n is negative. According to InputStream documentation:

If n is negative, no bytes are skipped.
It seems that ...

7. May the FileInputStream.available foolish me?    stackoverflow.com

This FileInputStream.available() javadoc says:

Returns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by ...

8. Does FileInputStream.skip() do a seek?    stackoverflow.com

I want to copy the last 10MB of a possibly large file into another file. Ideally I would use FileInputStream, skip() and then read(). However I'm unsure if the ...

9. FileInputStream is Null?    stackoverflow.com

Okay, so this is the line that's returning null. What am I doing wrong while creating this FileInputStream?

FileInputStream fin = new FileInputStream(new File(getClass().getResource("data/levellocks.lv").toURI()));





10. is there an existing FileInputStream delete on close?    stackoverflow.com

Is there an existing way to have a FileInputStream delete the underlying file automatically when closed? I was planning to make my own utility class to extend FileInputStreamand do it ...

11. What's better practice : To keep a fileInputStream open for a long time, or open and close it a lot?    stackoverflow.com

I've written a little app in java that writes a few lines to a text file every ten seconds or so. Is is better to initialise the input stream outside the ...

12. Do I have to close FileInputStream?    stackoverflow.com

I am working as a trainee in Test Automation. I am working with creating Junit code with Eclipse and run using Eclipse. In that I am retriving the datas from excel sheet using ...

13. Is there any possible way to create fileinputstream with mark supported feature?    stackoverflow.com

Is there any possible way to create fileinputstream with mark supported feature as true ?

14. Internal working of FileInputStream    stackoverflow.com

I searched for something in Java to read the file. I found FileInputStream and DataInputStream, but I wanted to know the internal working of this stream. Can somebody explain me clearly ...

15. What is wrong with FileInputStream.read(byte[])?    stackoverflow.com

In response to my answer to a file-reading question, a commenter stated that FileInputStream.read(byte[]) is "not guaranteed to fill the buffer."

File file = /* ... */  
long len = ...

16. Equivalent to FileInputStream in J2ME?    stackoverflow.com

Is there any equivalent to FileInputStream in J2ME?





17. Unexpected behaviour with FileInputStream, JAVA    stackoverflow.com

I am in the process of writing an application that processes a huge number of integers from a binary file (up to 50 meg). I need to do it as quickly ...

18. FileInputStream null error    stackoverflow.com

import java.util.*;
import java.io.*;

@SuppressWarnings("unused")
public class search 
{
public static String[] inputdata;
public static String[] routedata;

public static void main(String[] args)
{
    inputdata();
    routedata();

}

public static void inputdata()
{
    String ...

19. How to implement RandomAccessFile's seek() and getFilePointer() using FileInputStream and BufferReader?    stackoverflow.com

I would like to Open a file containing UTF-8 encoded text, Can able to set position, Read 25 lines, Can able to get position. Unfortunately RandomAccessFile does not support UTF-8 encoding. So ...

20. Java FileInputStream with C like preprocessor built in    stackoverflow.com

I once found a FileInputStream or FileReader class (I believe it was from IBM on the developers web sites) but when I google right now I only find "preprocessing tools" that ...

21. Cant find the newline character in a file (java)    stackoverflow.com

I am trying to get the last line of a file, but my output shows that it never finds it. I also tried looking for "[" which all the lines start ...

22. Identify the current character being read in "read" method of fileinputstream?    stackoverflow.com

FileInputStream in = new FileInputStream("filetoreadfrom.txt");

while ((c = in.read()) != -1) {

Integer cobj = new Integer(c);
System.out.println("The Current data being read is :" + cobj.byteValue());
out.write(c);
}
The sysouts give an intvalue representing the byte being ...

23. I'm having trouble reading a properties file using FileInputStream    stackoverflow.com

I'm working on a web application, and I have created a properties file in package com.xx.yy. I need to read this file from a class in author package com.aa.bb I have the ...

24. Help! Please! Problem with FileInputStream    coderanch.com

I am developing a Java App that will read from a directory and use MQSeries to put the files from the directory on the queue. I got the code working for a file, but can't get it to work if I use a directory instead of a file. I can put the file contents on the queue but not the files ...

25. Is it possible to read a word document using FileReader or FileInputStream?    coderanch.com

Is it possible to read a word document using FileReader or FileInputStream? I am trying it in vain.The reading is giving some unknown characters. This is my snippet of code: //try{ finp = new FileReader("d:\\HelloWorld.doc"); // fout = new FileWriter("d:\\HelloWorld11.doc"); //while(finp.read()!=-1) //{ int intRead= finp.read(b); //fout.write(b); input = new String(b); System.out.println("" + input); //} finp.close();

26. FileInputStream.read(byte []) question    coderanch.com

I have the following snippet of code I'm using in a program and I wanted to know if there could be a situation in which the read method of FileInputStream would return 0 as the number of bytes read even though there is data available. ( What I was thinking of was a situation in which an exception is not thrown, ...

27. retrieve a file from a fileinputstream    coderanch.com

Depends what you mean by "retrieve the file". You can certainly read the contents of the file. But if you want to know the name and location of a file, there doesn't seem to be any way to do that. If you really need to find the file name, and have no other way to do this, I suppose you could ...

28. exception when using FileInputStream public int read(byte[] b, int off, int len)    coderanch.com

Hi, Welcome to JavaRanch! Why are you calling this a FileInputStream problem when you're using RandomAccessFile, an unrelated class? The three arguments to "read" are the buffer to read into, the index of the first location in that buffer where the data should go, and and number of bytes to read. Since your buffer is only 5 bytes long, both the ...

29. FileInputStream inside of a .war file...    coderanch.com

I have a servlet that uploads a file , modifies it and sends it to the browser. Is it possible to have the file as part of the .war file and how do I access it using FileInputStream - I can't figure out what path to use - the FileInputStream can never find the path specified and I've tried a bunch. ...

30. FileInputStream    coderanch.com

Here I go again. I am attemptin to create a logon screen. I can create an ID and write to a file. However, I cannot pull the entire contents of the file back into the program to determine whether an ID and password are a match. Please see attached code below. import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; ...

31. FileInputStream    coderanch.com

You'll have to read the contents of the stream to a byte array (or String, depending on the contents), and send that as a return value to the client. Even if you did manage to send a reference to a FileInputStream to the client (which you can't, since it's not Serializable), I wouldn't think that there would be any way for ...

32. FileInputStream vs. Random Access File (Read Performance)    coderanch.com

Hello out there, I have a little question to Random Access Files (I have never used them since now). I have to read very large files, since now I'm doing this with FileInputStreams. Now I have the problem that in some cases I dont need the first bytes (Megabytes...Gigabytes...very large files) of a file. Which solution would you prefer? I could ...

33. FileInputStream problem    coderanch.com

PLEASE EXPLAIN LINES MARKED BETWEEN ***** IN THE PROGRM GIVEN BELOW I GOT THE FIRST PART IN WHICH WE READ FIRST FEW BYTES FROM THE FILE //CODE import java.io.*; class FileInputStreamDemo { public static void main(String args[]) throws Exception { int size; InputStream f = new FileInputStream("C:\\Orahome1\\jdk\\bin\\TwoObservers.java"); System.out.println("Total Available Bytes: " + (size = f.available())); int n = size/40; System.out.println("First " ...

34. FileInputStream Not Working    coderanch.com

35. question on FileInputStream    coderanch.com

36. mark () in FileInputStream    coderanch.com

FileInputStream does not support mark(). You could find this out from the API documentation, although it's not super-obvious. Base class InputStream implements markSupported() to throw false and mark() to do nothing, so any subclass of InputStream that does not override markSupported() and mark() cannot support mark(). FileInputStream does not override them, so it cannot support mark(). BufferedInputStream does support mark(). Wrap ...

37. FileInputStream Exception - Bad file descriptor    coderanch.com

Hi. I am trying to learn about compression and have fallen at the first hurdle. The following code gzip's files: import java.io.*; import java.util.zip.*; public class Compressor { public static void gzipFile(String srcFileName, String destFileName) throws IOException { FileInputStream fis = new FileInputStream(srcFileName); FileOutputStream fos = new FileOutputStream(destFileName); GZIPOutputStream gzipOut = new GZIPOutputStream(fos); byte[] buf = new byte[4096]; int bytesRead; while((bytesRead ...

38. Doubt on FileInputStream    coderanch.com

Here is my program :- import java.io.*; class Test { public static void main(String[] args)throws Exception { write(); read(); } public static void read()throws IOException { FileInputStream in = new FileInputStream(new File("out.txt")); int data=0; while(data != -1) { data = in.read(); if(data != -1) { System.out.println(data); } } } public static void write()throws IOException { FileOutputStream out = new FileOutputStream(new File("out.txt")); ...

39. FileInputStream & Negative Bytes...    coderanch.com

Is there a way to have a file input stream not return negative values? Currently I'm using one to read a file that starts with the bytes: 6F 61 FE The integer output of these should be: 111, 97, 254 repectively. However, I'm getting: 111, 97, -2. Is there a method that reads unsigned bytes like in the ImageInputStream Class?

40. FileInputStream large files    coderanch.com

Im developing in java 1.4.2. Im using a FileInputStream to read in (1MB) chunks of a large file and transfer them to another machine which is read to write the chunk to a file. Im getting an out of memory error reading in the file (after about 60mb) any ideas? Have a feeling that there is some zombie references sitting about ...

41. FileInputStream    coderanch.com

You can also do the following: FileInputStream aFileInputStream = new FileInputStream("filename"); //initialize a byte array with the size in bytes of the file //FileInputStream.available() returns that size byte[] bb = new byte[aFileInputStream.available()]; aFileInputStream.read(bb); aFileInputStream.close(); You should of course use Try/Finally blocks around all this to ensure that any exception still results in the aFileInputStream.close() being executed

42. FileInputStream Initialization...    coderanch.com

The uninitialized error comes about because the compiler thinks you might get down to the read code without successfully initializing that variable to anything. You can make it go away by intializing to null, or by the syntax you showed. I like your way better - don't declare the variable even a line before you need to use it. The return ...

43. make FileInputStream out of InputStream    coderanch.com

44. FileInputStream error    coderanch.com

Hi We are trying to read a properties file using FileInputStream in our j2ee app: LogManager logManager = null; try { FileInputStream inputStream = new FileInputStream("MY_logging.properties"); System.out.println(" FileInput stream "+inputStream); logManager = LogManager.getLogManager(); System.out.println(" Log Manager "+logManager); logManager.reset(); logManager.readConfiguration(inputStream); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } The properties file is in a jar defined as a utility jar within the ...

46. FileInputStream problem    coderanch.com

You can't write to resources. Ideally the application path would be available like with programs written in Visual Basic (for instance), but that's not the case. What you can do is use a user-specific location to store your files: String home = System.getProperty("user.home"); File path = new File(home, ".yourapp"); File propertiesFile = new File(path, "newproperties.properties");You can then load from the resource ...

47. FileReader vs FileInputStream    coderanch.com

Welcome to JavaRanch. It's not a question of efficiency, it's a question of functionality. Streams work with binary data, while Readers (and Writers) work with character data. If binary data can be converted to character data (and not all binary data can), then you'll need to consider the encoding that was used to convert the character data to binary data in ...

48. FileInputStream    coderanch.com

49. FileReader vs FileInputStream    coderanch.com

Readers and Writers are for character (text) I/O, while Streams are for binary I/O. Those may at times appear to be the same thing (text can be handled using streams, too), but every time a Reader/Writer is used one needs to think about handling encoding/decoding issues. Using streams one can focus on handling bytes.

50. FileInputStream password problem    coderanch.com

51. Why does FileInputStream's read() method return integer?    coderanch.com

If you think it's possible for an input stream to return any byte it reads as data, and also return some specific byte to indicate there is no more data, then you should tell us what byte that would be. So think about it. What byte would you choose to indicate there is no more data available? Bear in mind that ...

52. How to modify FileInputStream?    coderanch.com

53. Doubt regarding FileInputStream    coderanch.com

54. FileReader and FileInputStream    coderanch.com

55. Empty FileInputStream..    java-forums.org

File file = new File("image1.jpg"); FileInputStream fin = new FileInputStream(file); FTPClient client = new FTPClient(); String filename = "image.jpg"; client.storeFile(filename, fin); fin.close(); I use that code to store an image to my server. It works an image gets saved as image.jpg. The width and the heigth of the image are equal to those of the bufferedimage, but the whole image is ...

56. FileInputStream    java-forums.org

Hi, I'm trying to understand how the syntax of FileInputStream works... I'm supposed to get input from the user of a name, then search a text document, which has a name on each line, to see whether that name is in the directory. How can i achieve this with FileInputStream.. can someone show my some example code?

57. FileInputStream not recognising file    java-forums.org

{teachPanel.setVisible(true); questPanel.setVisible(false); File f = new File(thingsName+".zzz");// set to existing file chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setSelectedFile(f); int returnVal=chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION)//file selected {File curFile=new File(""); curFile = chooser.getSelectedFile(); System.out.println("File Type= "+curFile);} else {return;} //read file here try {FileInputStream f_in = new FileInputStream (curFile); //problem line ObjectInputStream obj_in = new ObjectInputStream (f_in); Object obj=obj_in.readObject(); scores =(int[][]) obj; //cast obj to array Object obj1=obj_in.readObject(); props=(String[])obj1; ...

58. FileInputStream Problems.    java-forums.org

private void initComponents(){ MenuItem Open = new MenuItem(" "); MenuItem Exit = new MenuItem(""); Menu File = new Menu(""); Menu Edit = new Menu(""); File.add(Open); File.add(Exit); Open.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){OpenFileDialog dialog = new OpenFileDialog(); javax.swing.JOptionPane.showMessageDialog(dialog, "File Opened"); File file = dialog.chosenFile; FileInputStream stream = new FileInputStream(file);// error here GasWaterRecordsProcessor processor = new GasWaterRecordsProcessor(stream); gwpanel.flipPage(0);} }); Exit.addActionListener(new ActionListener(){ public void ...

59. FileInputStream    java-forums.org

60. FileInputStream    java-forums.org

How to load an excel file and store the values of that file in an array.I have written a program but it is printing garbage values.It is as follows. import java.io.*; class FileDemo { public static void main(String[] ar) throws IOException { InputStream f=new FileInputStream("E://ex1.xlsx"); n=f.available(); byte b[]=new byte[n]; f.read(b); for(int i=0;i

61. FileInputStream Referencing (Probably Really Easy)    java-forums.org

Hi, I need to reference a FileInputStream (FIS) in a method but it is not letting me. The FIS is in my constructor and I the only solution can think of is taking it out and creating it at the top of my class but Eclipse is saying no because of necessary try and catch statements. How can I enable referencing ...

62. Compare FileReader and FileInputStream    java-forums.org

63. cant pass file from a dir to fileinputstream()    forums.oracle.com

hi ! i am stuck here ..please help. I have an application that creates a dir called temp in home directory . and and a file which is named in following format. for example 080718002220.txt i.e. systemdate.ext type . Since this files are created in real time and has no specific file name .How would i pass it to fileinputstream() . ...

64. entering file names for a FileInputStream    forums.oracle.com

65. FileInputStream    forums.oracle.com

66. FileInputStream's read() outputs differently when not stored in a variable    forums.oracle.com

You can't "assign" a method to a variable, what you're doing is assigning the resulting value from the call to the method. As for read(), imagine you have a counter which says which byte is going to be read next, or an imaginary stack containing the bytes, each read you either read the byte at the counter's position, or pop the ...

67. about FileInputStream    forums.oracle.com

68. Issue with close() method of BufferedReader class and FileInputStream class    forums.oracle.com

Jay-K wrote: 1. Is it necessary to call close method in this senario? Yes! Always! And why? [it seems to me that everything gets cleaned up automatically anyways at the end of each call to the method when called from main()] To avoid resource leaks. To automatically flush the stream. To close any subsequence streams. 2. If the answer for No.1 ...

69. How to use FileInputStream    forums.oracle.com

70. Question about FileInputStream.read()    forums.oracle.com

When I translate the VB.NET to Java, I found that Java has not unsigned byte so I change them to int[]. But it has not "read(int[] i, int off, int len)" and it seems not to have the method that change the current byte read.... How can I read the file? Or read(byte[] b, int off, int len) can store the ...

71. open FileInputStream using ClassLoader    forums.oracle.com

Ok, then what you tried here: InputStream is = getClass().getResourceAsStream(fileName); will work, as long as fileName is properly specifying something findable on the classpath. It should be of the form: /path/filename.ext assuming that one of the JARs on your classpath, or one of the classpath roots, provides access to that. For example, let's say your classpath is: C:\stuff;C:\myjars\somejar.jar As long as ...

72. total fileinputstream.available()    forums.oracle.com

If you want to know the size of a file then the length() method of java.io.File is what you should use. If you want to know the total size of all files in a directory then yes, you're going to have to write a loop to add up those numbers. You can get a list of all files in a directory ...

73. Pause fileinputstream    forums.oracle.com

74. FileInputStream    forums.oracle.com

ZipFile zFile = new ZipFile(tempFile); Enumeration zipEntries = zFile.entries(); String logFile = null; String fExtn=null; String gbsFile=null; while(zipEntries.hasMoreElements()) { ZipEntry zEntry = (ZipEntry)zipEntries.nextElement(); String fName = zEntry.getName(); fExtn = fName.substring(fName.length()-3); fName=fName.substring(fName.indexOf("/")+1); File f; File fDir = new File(TMPHome+" BRCFiles"); fDir.mkdirs(); f=new File(fDir,fName); FileInputStream fis=new FileInputStream(f); BufferedInputStream inr= null; FileOutputStream fout=new FileOutputStream(f.getPath()); BufferedOutputStream out=new BufferedOutputStream(fout); byte [] fileData = null; int readCount=0; ...

75. FileInputStream vs FileReader    forums.oracle.com

76. File Chooser - FileInputStream    forums.oracle.com

78. how does fileinputstream know where my file is located?    forums.oracle.com

Just like almost anything you do with files, you can give it an absolute path or a relative path. If you provide a relative path, it will be relative to Java's notion of your current directory, which can be obtained from the system property "user.dir". If you started Java from the command line, it will be whatever your directory was in ...

79. Reading a file: FileInputStream x FileReader    forums.oracle.com

80. Passing parameters to FileInputStream    forums.oracle.com

81. read exclusive lock FileInputStream    forums.oracle.com

82. Opening FileInputStream() deletes my files    forums.oracle.com

83. FileInputStream    forums.oracle.com

84. Weird with FileinputStream    forums.oracle.com

I saw some weird behaviour, don't know why. I did the following: File f = new File("abc"); 1. FileInputStream fin = new FileInputStream(f); 2. InputStreamReader in = new InputStreamReader (fin); 3. BufferedReader br = new BufferedReader(in); 4. Read everything from br.read 5. BufferedInputStream bin = new BufferedInputStream (fin); 6. WHEN I READ FROM STEP 5 I GET GARBAGE 7. Now I ...

85. FileInputStream issue    forums.oracle.com

Greetings all: This is my first message so I'll introduce myself as well. I've been programming in various languages since 1993 and have worked as a contractor, programmer analyst with Nortel and now I'm a senior developer with the Government of Canada. I would also like to mention that I've had complete loss of sight since 1992 but despite the obvius ...

86. FileInputStream trouble    forums.oracle.com

Hello, I'm working on a program that reads in files then transfers them across a network to be stored on a server. The program works fine but the reading in of new files on the client side is extremely slow. Heres a snippet of the file input stream. in = new FileInputStream(text1.getText()); int c; while ((c = in.read()) != -1) { ...

87. FileInputStream and what sizes of files it's capable of handling    forums.oracle.com

Thanks for the suggestion, this is pretty frustrating. It seems like the FileInputStream has a maximum file size it's capable of handling. Because .available() returns an int, presumably this is Integer.MAX_VALUE number of bytes. If that were the problem, I would work around it and go find another API. But the problem is that when I open a 9 gigabyte file, ...

88. FileInputStream    forums.oracle.com

Yes because you are not passing the array to the FileInputStream, you are simply passing one of the array's elements, which happens to be a string so you are fine. BTW, your variable names should start with a lower case. You do not need to initialize the string array via the 'new' operator. - Saish

89. Process error: java.io.FileInputStream@11b86e7    forums.oracle.com

i have already gone through the link u have forwarded! If i want to execute a batch file without parameters (like D:\run.bat") then it works fine, But in my case there are arguments also for the batch file which i'm trying to execute testcollector.bat param.txt any.any.JreInfoV1 Problem is with the arguments i guess!!! N why exitValue=1????? It should be 0 normally ...

90. Using FileInputStream to view File Details.    forums.oracle.com

You're reading into a variable called line, then adding to your string buffer from a variable called b. You're not using the value you've read into line. When reading text files, I always use a BufferedReader, I find it more convenient. You may want to go look for an example of how to.

91. Accessing file with FileInputStream from a different directory    forums.oracle.com

Hi Could someone tell me how can I read a file say "map.txt" from a directory other than the one the project is in, please ? my directory structure is "Map" directory has 2 folders insise: -> Folder1 (where is my project) and -> Folder2 (where is "map.txt") and I have : FileInputStream fos = new FileInputStream("/Folder2/map.txt"); but it doesn't work ...

92. How to determine if a FileInputStream is open?    forums.oracle.com

How can you determine if a FileInputStream or (FileReader or BufferedReader) is open? I am looking to copy files to different directories depending upon which exception is thrown. But in order to copy a file first, you must first close the FileInputStream. But I want to first check to see if the FileInputStream is open. thanks

93. Problem with FileInputStream over MacOs X    forums.oracle.com

Hello, I have a problem to copy file in MacOs X. I have the following function to copy files: private void copy (String fitxer) { try { File src = new File(fitxer); File dst = new File(PATH + src.getName()); InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > ...

94. Help with FileInputStream    forums.oracle.com

95. fileinputstream    forums.oracle.com

Hi all, I have a XML file (template) in which I need to make some modifications in runtime. After that I need to send the result as a parameter of type FileInputStream to some function. Here is my code: FileInputStream templateStream = new FileInputStream("template.xml"); String text = templateStream.toString(); ... text modification ... Now I need to know, how to change the ...

96. fileinputstream    forums.oracle.com

97. Compare FileReader and FileInputStream    forums.oracle.com

import java.io.FileInputStream; import java.io.IOException; public class PrintFileByteData { public static void main(String[] args) throws IOException { FileInputStream is = null; try { is = new FileInputStream("input.txt"); int b; while ((b = is.read()) != -1) { System.out.println(b); } } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { is.close(); } } } }