Hi guys, It has been a while since I have touched Java, so I know this is a fairly simple task, but can't really think of what mite be the best way to accomplish it. Anyway, basically I have an .xml file with a particular piece of information that I want to extract and look at, the basis of the program ... |
|
|
Hi everybody: im trying to make a compiler simulator, but im stuck from the first step cause when i opened the .java file and i tried to add the character to a string with datainputstream.readChar() method to procces it , the string finalizes with a bunch of weird chinese characters, what im doing wrong. Thanks in advance. |
Hi Everyone, I had a read file function that readline from file, how can I read char by char so that I can get the carriage return value? public String ReadFile(String filename){ BufferedReader inputStream = null; String inputText = ""; try { FileReader file = new FileReader(filename); inputStream = new BufferedReader(file); } catch(FileNotFoundException e) { System.err.println("File not found: " + filename); ... |
|
|
|
When a decoder encounters a byte (or sequence of bytes) that doesn't represent a character in the given encoding, it appends a standard replacement character (usually '?') to the output. So if you decode the byte stream incorrectly, you can't necessarily reconstruct it from the decoded character sequence. You should always reread the bytes from the file. |
Hi, I want to read SECOND ROW of a csv file(i.e Header) .First row of the csv file contains a File Identifier, second row contains HEADER and following rows contain the records. I want to do it by using readLine() function on a object of type BufferedReader. Please suggest how can i do that |
I want to be able to read just few files at a time in a given directory. File Class provides .list() but it gets all the files or if I use FileNameFilter then based on file name - still it will try to read all the file names. But what I want is to read few files. We have 3 million ... |
|
|
hi experts, i've designed a search runnable class. it searches for particular (matched) items in RSS(XML) documents stored on local drive, let say just 2000 files. the matched items then appended in JTable. i've 2 problems right now. 1. sometimes my application gives "out of memory" exception during all above process, normally it happened after 500 or 600 files read. 2. ... |
Hi All, I am looking for the way to read the file with contains records in multi lines, only way to distinguish between records is start string "TES 001-" is my case Sample record is NameofFile=sample.txt 001 TES 001-00017578442P1060054J799 4630106518W6E 999350975147 65 & 0000a TES 00110 U$U$ U$ 0000a TES 00124000-6000- 0000a TES 0013 RTRAN41832900014RTRAD425104 0000a TES 001-00017578442TES1060054J799 9910999318 424250975147 65 ... |
try { fis = new FileInputStream(f); WordExtractor we = new WordExtractor(fis); String contents= we.getText(); reader = new StringReader(contents); } catch (FileNotFoundException e) { System.out.println(" file not found exception in doc" + e.getClass()); e.printStackTrace(); } catch (Exception e) { System.out.println("exception in doc " + e.getClass()); e.printStackTrace(); } finally { if (fis != null) { try { fis.close(); } catch (IOException e1) { ... |
try { document = builder.build(new File(FILE_PATH)); return; } catch (IOException ex) { setIsError (true); } catch (JDOMException ex) { setIsError (true); } } //if config file is existed do this public void setConfigFromFile(){ org.jdom.Element infor = document.getRootElement(); defaultValues.setDatabaseName(infor.getChild(DB_PARAMS).getChild("name").getText()); defaultValues.setHostName(infor.getChild(DB_PARAMS).getChild("host").getText()); defaultValues.setPortName(infor.getChild(DB_PARAMS).getChild("port").getText()); defaultValues.setUserName(infor.getChild(DB_PARAMS).getChild("username").getText()); .... /* * No config file, create an empty config.xml file */ private void createEmtpyConfigDocument(){ document = new Document(); Element ... |
|
18. File Read forums.oracle.com |
I have an applet that needs to use methods that read a specific file. The file is on my computer and I don't need the applet to access any of the end-user's computers but I can't figure out how to make it access that file without getting an AccessControl exception. Please help. |
} private void jButton6MouseClicked(java.awt.event.MouseEvent evt) { //vector to hold all the firearms once returned Vector v = new Vector(); Firearms aGun; try{ FileInputStream fis= new FileInputStream("C: Guns.tmp"); BufferedInputStream bis = new BufferedInputStream(fis); ObjectInputStream ois = new ObjectInputStream(bis); aGun = (Firearms)ois.readObject(); v.addElement(aGun); jComboBox1.addItem(new String(aGun.getManf() + " " + aGun.getModel() + "-" + aGun.getSn())); ois.close(); } |
|
How are you subsequently displaying this text? You clearly have an encoding mistmatch somewhere, it could be the file isn't actually UTF-8 encoded (perhaps it's a german national encoding, or codepage), it could be that you are writing to a console with the wrong assumptions about what codepage the console is using. |
|
Can anyone explain what the difference is? Is it simply that passing st.nextToken() to the vector instead of a new String leaves references that does not allow garbage collection to free each line after it is processed? Why would storing the same number of strings created by new String() be so dramatically different than just passing the original ones? (if that ... |
For each jsp file my parser create a java file. It also create a map file which holds information as which line number in java corresponds to which line number in jsp as some statements are being added by the parser. Now i have also generated a bdf file which holds information if any problem exist in the java file. As ... |
Hello everybody, I try to read arabic unicode signs from a file into a String within my program. I create the file using simple windows notepad. The sign Im wrinting look perfectly arabic (although I actually cant read it). Now when I start my program and read the signs it doesnt read arabic signs but signs that are within the Unicode ... |
|
Are all the files in one directory? If so you can make a File object of the directory, get an array of all files in that directory (File has a method to do this). Then loop over your array and call a method that reads the File that you pass as a parameter. |
hi. i've got an issue. my code is prepared for one file reading: FileReader fr = new FileReader(file_name); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("out.txt"); now i have to read a hole directory in a loop for example and write it to one out.txt. how can i do it, what should i put into: FileReader(?)?. thanks for any ... |
available() only returns the amount of bytes that can be read without blocking. Your code is completely wrong. You need to do read(byteArray) in a loop, where the byte array is a suitable size (for example 8 kilobytes). The read(b) method returns an integer telling you the amount of bytes it actually read, then you can write that many bytes from ... |
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // Properties prop = new Properties(); File file = new File("properties.txt"); String username = null; String user = null; try { FileReader fi = new FileReader(file); BufferedReader bf = new BufferedReader(fi); // StringBufferInputStream sb = new StringBufferInputStream("properties.txt") username = bf.readLine(); String password = bf.readLine(); System.out.println(username); ... |
hi, i've got a text file(about 20,000 lines) such as: 1 - NETWORK ENTITY INFORMATION NE ident Num : 00000037226 Extension Lev : System SW vers : 020805010027 NE Type : C Mother NE : Total Capacity : Capacity Part1 : Capacity Part2 : I wanna separate those lines to csv file: value,value,value.... How can i fast as possible read this ... |
|
|
|
Why not use indexOf or startsWith in the String class, if a line does not start with a specified String then it skip the line. IO is quick in Java, I don't think you will notice any difference for whatever approach you use. Doing a bit of screen scraping are we? Hope you check the source for any legal stuff. ,-) ... |
|
|
|
ok your problem is that each time you call br.readLine() it reads the next line in grocery.dat. i dont know how grocery.dat is structured i.e. how the data is saved in the file so i cant comment on how u are accessing the the paramters associated with each item in the file if you could show that file it would be ... |
|
Text file: busstop UEA busstop Riverside busstop RailwayStation busstop Unthank junction roundabout junction colman2 junction blue1 junction earlham1 junction colman1 segment UnthankRd Unthank RCCathedral 1.000000 20.000000 segment StStephensStreet StStephens CastleMeadow 0.700000 15.000000 segment SouthparkAv blue3 colman2 0.710000 20.000000 segment ChapelFieldRd RCCathedral StStephens 0.600000 20.000000 segment ColmanRd1 roundabout colman1 0.260000 25.000000 segment EarlhamRd1 fiveways roundabout 0.480000 25.000000 segment EarlhamRd2 roundabout Earlham 0.350000 ... |
|
I have a file named 'temp.conf'. In that file there are some lines like x = y temp = variable And i want to write some data into the existing 'temp.conf' file (same format as above). suppose i have to write 'sample = tree '. While writing i have to check whether this string is available in the file . If ... |
I have a text file that I have created in Default Unicode font. In this file I have some "special" characters. These are the euro symbol, the British Pound symbol and 1 other character that I don't know the name of but looks like this . I have code that is trying to read this file in by creating a BufferedReader ... |
Inside that loop either read the object (and ignore it) or seek beyond it before attempting to read the next int. Whether you want to use the object or not is irrelevant. It still exists in the file, and so you have to account for it, either by reading it, as ejp said, or seeking beyond it. Edit: In other words, ... |
|
Using FileInputStream and DatainputSTream to read a file. The file is too big (16 MB). I search for a variable in it till its end and then I search for other (loop on variable).When a file reaches its end (by readline()!=null) ,is there any way that I can be on start of file again?Because if I again create Stream for the ... |
|
|
Hi all, I was wondering if anyone knew the best way to 1)Read in a single line of a file until a given character and convert each character to an integer 2)Also if their is a way to count the number of lines in a file and then only choose a line number to read in or would i have to ... |
Hello, Sorry for this dissertation but it is necessary in order to understand what is going on: I have created a Bank system for a course (already graded so this is for my own knowledge). In this system I have an ArrayList of BankAccount types being written to a file via an ObjectOutputStream, each of these BankAccount objects contains some number ... |
I have a txt file with the following numbers: ..1..3 ...... ....2. 26.... ...3.. 3..1.2 I want to read this to the console and convert the dots into string = "0". First I read the other numbers as string, but later I convert them to int. There the 0 must convert to string first. The output on the console should look ... |
FileWriter fw1=new FileWriter("D:/data/java1.4.2/bin/matchid.txt"); BufferedWriter bw1=new BufferedWriter(fw1); int k=0,check1=0,count=0,i=0; String cstr=null,id=null; long len; len=raf1.length(); boolean b1,b2; while((str=raf1.readLine())!=null) { //reading the new line, n extracting the string to be matched if(check1==0) { k=k+1;//reading new line StringTokenizer cst = new StringTokenizer(str,":"); while(cst.hasMoreTokens()) { cstr=cst.nextToken(); count=count+1; if(count==4) { if(cstr.length()==15) { id=cstr; bw1.write(str); // System.out.println("first "+str); match.write('\n'); check1=1; count=0; break; } } }//end of while count=0; ... |
class Getimg { public static void main(String[] args) throws IOException{ EditorKit kit = new HTMLEditorKit(); String file ="imgsrcs"; Document doc = kit.createDefaultDocument(); FileOutputStream fout= new FileOutputStream(file); PrintStream p = new PrintStream(fout); // The Document class does not yet handle charset's properly. doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE); try { // Create a reader on the HTML content. Reader rd = getReader(args[0]); |
I'm sure this question gets asked a lot ... I searched on the forums already and the pages I tried to look at all came back as blank. (maybe they were too old or something..) Anyway - I'm trying to read just a plain text file into my program to display into a JTextFrame. I've looked at a lot of documentation ... |
Hi, I have a variable block file which was transmitted from mainframe side. When i browse the variable block file in mainframe i can see it as !Line 1 !Line 2 !Line 3 but once we transmit the file in Unix box, the file contents appear as !Line1!Line2!Line3 does java differentiate between variable block and fixed block files.. does java has ... |
C:\assignment 4\actual assignment\cars.java:13: incompatible types found : int required: java.lang.String for (String index = 0;index < 5;index++) ^ C:\assignment 4\actual assignment\cars.java:13: operator < cannot be applied to java.lang.String,int for (String index = 0;index < 5;index++) ^ C:\assignment 4\actual assignment\cars.java:13: operator ++ cannot be applied to java.lang.String for (String index = 0;index < 5;index++) ^ C:\assignment 4\actual assignment\cars.java:16: incompatible types found : ... |
|
Hello folks.... can i resolve this problem or bug? In the range from x80 to x9f the instruction .read() return incorrect values. I read in the bug database (Bug ID: 4421413 ) that this is a natural consequence of the default encoding on windows which is cp1252. can i resolve this problem or bug? Thank's in advantage!! |
|
I'm able to connect to a website and read in the HTML fine, I now need to be able to get rip of the HTML coding, which will leave me with only the text. So if I was to read in this website: http://news.bbc.co.uk/1/hi/world/africa/6220797.stm Then all I want is a string that holds the story text. How is the best way ... |
My application writes to a log file. I want to read the end (say last 100 lines) of the logfile and display it on a web page. I dont want to read the entire log file as everything apart from the last 100 lines is irrelevant. Is there a way to do this? The only thing i can think of is ... |
|
Hey, i need my program to all the user to read in a file, send it to someone esle and then print it, because i want it to support any file type i think it would be best to use a byte array as the collection type. i have to use 1.5 and i was wondering does the scanner class support ... |
You can of course read the first token of a line and 'jump' (as you put it) to the next line - you just call a new readLine() method on a BufferedReader! This will return the next line. I'm not sure why you think this is not possible. If you re-read my post you will see that I used the StringTokenizer ... |
|
Hi all I need to chunk and read records from a fixed length file one bye one the logic to be implied should have following feature The start of the record is indicated by literals 01 till you encounter next 01 its the same record the code developed till now looks like import java.io.*; public class FileIO { public static void ... |
Hello, I need some help for reading an integer size element from a file. In C++ there is the function fread with the following signature size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream); where size is the size of one of the elements. Using this function in c++, you can read an integer by setting size = sizeof(int). I need ... |
Is it possible to read from files that are not *.txt files. For instance, microsoft word, microsoft excel, and whatnot? When I read from Microsoft word I always get garbage embedded with the text contained in the file. Can Java do this or do I have to use another programming lanuage? Thanks. |
|
|
|
Dear All; I am trying to read data from 3 files and group each similar line from the files into an array (ie. all entries of line 1 togather, all entries of line 2 togather ect). eg: File 1: File2: File 3: A B D B C C C C B After reading and grouping each similar line from the three ... |
75. Read Files forums.oracle.com |
Hi, I need to make an integration between two existing IT systems. The source system outputs the data as XML files to a (Windows) folder. My Java application reads the files, makes an XML transformation and writes the output files to target (Windows) folder. The target application reads the files from output / target folder. The problem is related how to ... |
I'm not familiar with that class and I don't see how it helps me calculate dates from a specific set date, but this isn't my main concern, what i really neeed help on is understanding how vb stores it's dates in a file, so that i can read and translate them into java. |
The best and standard way is to do it using FileInputStream and FileOutputStream See the code below : File inputFile = new File("any1.txt"); File outputFile = new File("any2.txt"); FileInputStream a = new FileInputStream(inputFile); FileOutputStream b = new FileOutputStream(outputFile); int i ; while ((i = a.read()) != -1) { b.write(i); You can change this to ask the user to specify the inputfile ... |
|
|
I have log file i need to read the file and retrieve some contents to anotherf file. Foreg:567 i write the code but i could not know how to write the code for dynamically generated contents... For eg:this time ticket no is 567..Next time reading the log file it may be any nmber or string.For Eg:456 or any string... Can any ... |
|
|
|
|
|
If I have a shortcut (let's say it's a windows link: c:\foo.doc.lnk) that points to a file in another location (D:\foo.doc) how can I access the original file through the link in order to retrieve the following information of the original file: full path, last modified time, and custom properties.? If I use the File.lastModified() method on the link, I get ... |
|
Whatever an 'ARPA file' may be, you read it the same way you read any other file. FileInputStream or FileReader. If you want to read native datatypes from the file, DataInputStream around a FileInputStream. If it contains lines of text, try BufferedReader.readLine. If you have to parse the text, take a look at java.util.Scanner. |
We have a proprietary application that creates temporary XML files which contain all the report information about the parameters selected, tables used, aliases, etc. It deletes these files immediately after they are passed to their reporting engine. I am writing an augmented reporting tool. I setup a listener using org.apache.commons.vfs.impl.DefaultFileMonitor. Sometimes I am able to get the entire file. More often ... |
I am trying to read a file roughly 340 GB in size. Yes, that's "Three hundred forty". Yes, gigabytes. (I've been doing searches on "big file java reading" and I keep finding things like "I have this huge file, it's 600 megabytes!". ) "Why don't you split it, you moron?" you ask. Well, I'm trying to. Specifically, I need a slice ... |
reis3k wrote: So, I just iterate through every 4096 bytes of the file , and put the content to the byte[]. However, I didn't come up with a better idea, because when I wanna read this file again for a specific chunk (e.g frameID=15;), I have to start while loop from the beginning until I come up the frameId, then use ... |
|
Its reading the file and outputting just fine. I am having some problems on figuring out how to get it to add the numbers on each line, hold onto that value, and continue to the next line. I am assuming it would be something along the lines of an array but I am not 100% sure. Any push in the right ... |
Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal( "hello".getBytes()); if i just save skey.getEncoded() and then make a new cipher , the result of encrypting "hello" is different. first time : [B@119c082 second time :[B@1add2dd Edited by: 863868 on Jun 6, 2011 6:01 AM Edited by: 863868 on Jun 6, 2011 6:38 AM |
The second line in file contains 1.7 which is not int and the program keeps looping forever. That is why you do not see results. If you want to sum up only integers then add a call to Scanner.next: while(src.hasNext()) { if(src.hasNextInt()) { sum += src.nextInt(); count++; }else{ src.next(); // skip tokens which are not integers } } |