Having alot of trouble in file reading in java

i dont know. but i feel really bad that Java is a very good OOP language and i suck big time (not very bad but got frustrated) in reading and writing files. some of the time i have accomplish my task with the help of forums. anyways first i would like to ask 2 questions and then i will state my problem. say for instance if i have a file with name amount and dollars. how can i read it?
i know i can use string regex split method in order to split the line but how can i create a method to do some changes in the text file like i have a name, bank account # and amount to deposit in the text file. my question is how can i declare my method to read (Name) first column and price second column and amount to deposit the third colum?
Secondly if i have a text file and i would like to replace all <<A>> with the name and <<G>> with the age. if i wanted to do without reading a file no problem create a string and then use the replaceAll method ("<<A>>", "Jaan") but for some reason i can't do it when i read a file. yes i am searching on google to get more understanding in reading file. but anyone care to explain wil be great. God bless you my Son.
import java.io.*;
import java.util.*;
class ReadData {
     private Scanner s;
     private static final String EMPTY_STRING = "";
     private String line1;
     private static String lineTerminator = System.getProperty("line.separator");
     public static void main(String[] args) throws IOException {
          ReadData read = new ReadData();
          read.start();
     public ReadData() {
          s = new Scanner(System.in);
     public void start() throws FileNotFoundException, IOException {
          System.out.println("Enter the file name");
          try {
          String name = s.next();
          openFile(name);
          catch (FileNotFoundException e) {
               e.printStackTrace();
          catch (IOException e) {
               e.printStackTrace();
     public String openFile(String filename) throws FileNotFoundException, IOException {
          String line;
          String line2;
          StringBuffer document = new StringBuffer(EMPTY_STRING);
          File inFile = new File(filename);
          FileReader fileReader = new FileReader(inFile);
          BufferedReader bufReader = new BufferedReader(fileReader);
          while(true) {
               line = bufReader.readLine();
               if(line==null) break;
               document.append(line + lineTerminator);
              System.out.print(document.toString());
          return document.toString();
}

i dont know. but i feel really bad that Java is a
very good OOP language and i suck big time (not very
bad but got frustrated) in reading and writing files.
some of the time i have accomplish my task with the
help of forums. anyways first i would like to ask 2
questions and then i will state my problem. say for
instance if i have a file with name amount and
dollars. how can i read it?Just like you'd read any other file. How you interpret what you've read depends on the specific format of the file, which you've provided no information about.
i know i can use string regex split method in order
to split the line but how can i create a method to do
some changes in the text file like i have a name,
bank account # and amount to deposit in the text
file. my question is how can i declare my method to
read (Name) first column and price second column and
amount to deposit the third colum? What do you mean? You want to read the entire first column, from all lines, then the entire second column, etc.? Unless you know the length of each line ahead of time so you can use RandomAccesFile, you can't do that. If that's not what you mean, then please clarify.
Secondly if i have a text file and i would like to
replace all <<A>> with the name and <<G>> with the
age. if i wanted to do without reading a file no
problem create a string and then use the replaceAll
method ("<<A>>", "Jaan") but for some reason i can't
do it when i read a file.
Create a tmp file.
For each line {
  Read a line.
  Do the replacement on the string you read.
  Write the new line out to the temp file
rename the temp file to the original
anyone care to explain wil be great. God bless you my
Son.I'm not your son. Keep your god away from me.

Similar Messages

  • I am having alot of trouble with svg files is there some one well versed with adobe svg file

    I am having alot of trouble with svg files is there some one well versed with adobe svg file

    Clearing out cookies while in gmail helped me to get all functionality back. One of those sites must have messed with gmail. Thanks so much for the help.

  • I am having alot of trouble i want to use imessage but everytime i turn it on it turns on but doesnt work and it says verifying but its verifying my old number and i need it to verify my new number but it wont let me

    i am having alot of trouble i want to use imessage but everytime i turn it on it turns on but doesnt work and it says verifying but its verifying my old number and i need it to verify my new number but it wont let me

    You can likely download the last compatible version by:
    Starting when iOS 7 was released, Apple now allows downloading the last compatible version of some apps (iOS 4.2.1 and later only)
    App Store: Downloading Older Versions of Apps on iOS - Apple Club
    App Store: Install the latest compatible version of an app
    You first have to download the non-compatible version on your computer. Then when you try to purchase the version on your iPod you will be offered a compatible version if one exists.

  • Having alot of trouble with a query

    Hey, I'm having trouble with a query for an assignment. The questions states
    Find the name of the highest earning employee in each location, excluding managers, salespeople and the president
    The problem I'm having is that my query returns the highest earning employee from each location perfectly, but one of those returned is a salesperson, so the next highest earning person in that location should be returned.
    We are also not allowed to create a temporary table
    Here's my code so far
    select
    e.first_name,
    e.last_name,
    e.salary,
    l.regional_group
    from employee e
    inner join department d
    on d.department_id = e.department_id
    inner join location l
    on l.location_id = d.location_id
    where e.salary = (select max(e2.salary) from employee e2
    inner join department d2
    on d2.department_id = e2.department_id
    inner join location l2
    on l2.location_id = d2.location_id
    where l2.location_id = l.location_id
    and e.job_id !=672;
    the job_id refers to what job title they have
    and here's the schema below
    Schema
    Any help you could give me on this would be fantastic as I have been pulling my hair out over this for the last day.
    Edited by: 837562 on 17-Feb-2011 02:14

    Maybe you can try the below:
    with job_location as
    select 1 location_id, 'loc1' regional_group from dual
    union
    select 2 location_id, 'loc2' regional_group from dual
    department as
    select 1 department_id, 'dept1' dept_name, 1 location_id from dual
    union
    select 2 department_id, 'dept2' dept_name, 2 location_id from dual
    job_FUNCTION as
    select 1 job_id, 'MANAGER' job_function from dual
    UNION
    select 2 job_id, 'SALES' job_function from dual
    UNION
    select 3 job_id, 'PRESIDENT' job_function from dual
    UNION
    select 4 job_id, 'REST_1' job_function from dual
    UNION
    select 5 job_id, 'REST_2' job_function from dual
    employee as
    select 1 employee_id, 'a' last_name, 100 salary, 1 department_id, 4 JOB_ID from dual union
    select 2 employee_id, 'b' last_name, 200 salary,1, 5 from dual union
    select 3 employee_id, 'c' last_name, 300 salary,1, 2 from dual union
    select 4 employee_id, 'd' last_name, 400 salary,1, 2 from dual union
    select 5 employee_id, 'e' last_name, 500 salary,2, 3 from dual union
    select 6 employee_id, 'f' last_name, 600 salary,2, 3 from dual union
    select 7 employee_id, 'g' last_name, 700 salary,2, 4 from dual union
    select 8 employee_id, 'h' last_name, 800 salary,2, 4 from dual
    select
    regional_group, employee_id, max_salary
    from
    select e.regional_group, b.department_id, employee_id, salary, max(b.salary) over (partition by b.department_id order by b.department_id) max_salary
    from
    employee b,
    job_function c,
    department d,
    job_location e
    where
    b.job_id = c.job_id and
    b.department_id = d.department_id and
    e.location_id = d.location_id and
    c.job_id not in (1,2,3) 
    ) where salary = max_salary;
    "REGIONAL_GROUP"     "EMPLOYEE_ID"     "MAX_SALARY"
    "loc1"     "2"     "200"
    "loc2"     "8"     "800"

  • Binary File reading in Java

    can i read binary format file with java? if so, can you please suggest which class i should be looking into?
    Thanks

    FileInputStream

  • Need a fast ascii file reader in Java

    Hi,
    My application needs to read around 50000 small ascii (1-25lines) files. Currently I use the BufferedReader API to read ascii files.
    Can you suggest something faster than the below.
    Thanks
    private ArrayList<String> readDataFile(String fileName) {
    String lineData;
    List<String> fileContents = new ArrayList<String>();
    BufferedReader moFile=null;
    try {
    moFile = new BufferedReader (new FileReader (new File ( fileName)));
    while ((lineData = moFile.readLine()) != null)
    fileContents.add(lineData);
    } catch(IOException e) {
    myLogger.error("Exception caught while reading data file: " + fileName + e.toString());
    }finally {
    try {
    moFile.close();
    }catch(Exception e) {
    //Ignore
    return fileContents;
    }

    816417 wrote:
    Kayman: I will be using all the contents of the file.Yes, but how? You could speed up the processing by reading all the files into a database once, unless these files are for example created every day and you need to always read the new ones.
    I don't have a prototype to provide the absolute time, a jprobe on my application shows that it takes 70% of the time.Yes, but your whole application takes 100% of the time. Do you have reason to believe that 70% is too much of time? What does the other 30% do?
    I want to reduce the time spent in this method.You want or you need to?

  • File reader and comparing words

    hi, im currently trying to create a project and i need a little help to get it started!
    What i need to do is create an application which can read a text file. I also need to have a list of words already in the application, and if a word in the list is also in the text file, id like this to be printed in the terminal.
    can anybody help me out with how to start this? ive been looking for relevant posts, and there seems to be alot of things on file reading and comparing words, but they r pretty difficult to follow and not really the same as what im looking for.
    thanks for your help!
    Torre

    You can place a for loop within a for loop to to compare every word in the temp array with every word in the other array.
    try {
    String[] array = new String[] {"wow", "cool"};
    BufferedReader in = new BufferedReader(new FileReader("text.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String [] temp = null;
    temp = str.split(" ");
    for (int i = 0 ; i < temp.length ; i++) {
      for(int j = 0; j < array.length; j++) {
        if (array[j].equals(temp)) {
    System.out.println(temp);
    } catch (IOException e) {
    } finally {
    //Always close your resources in your finally block... good coding practice.
    in.close();

  • JPEG file reading wierd bug using ImageIO.read and buffer strategy

    OK I have a slightly (!) bizzare problem. I have a program in Java 1.5.0 /5.0 which is fundamentally using a full screen exclusive mode window to display images loaded from files using ImageIO.read(file). I am getting the graphics context of the buffer strategy used on the FSEM window, and then drawing onto that the image that I have loaded using graphics.drawImage(ImageObj, 0,0, null).
    Now ordinarily this works fine, but I have (after much head scratching) discovered that certain specific jpeg images cause me problems. If I load one of these jpeg images, then it loads in with ImageIO.read fine and I get no errors, but the program locks up on the drawImage(ImageObj, 0,0,null) command in the rendering engine. It doesn't crash, but the CPU usage goes to 100% and stays there, and the method never returns. The image is never displayed on screen obviously, as the program never gets to call bufferStrategy.show() for these images. I have to forcibly terminate the VM to get out of the program.
    Does anyone know what is going on here? Is there some extraneous meta data in the dodgy jpeg files that is doing this? I don't know what 'extras' you can have stored on a jpeg that would cause this behaviour, and I don't know what restrictions there are in the jpeg file reader in Java.
    Its not a major bother to me (now I figured out whats causing it!), as I can just resave a duff jpeg in my image editing app and it will work fine. I just don't know whether I should submit it as a bug or not, and also I thought it would be useful for others to know of this strange behaviour - if I had known about it I would have saved myself about 8 hours!
    Thanks
    Alex

    Oh I forgot to add - I am resizing the images to the screen size using
    Image.getScaledInstance(deviceBounds.width,
    deviceBounds.height,
    Image.SCALE_AREA_AVERAGING);
    and then drawing the scaled image onto the graphics context.

  • I am having trouble establishing file association between .PDF files and Adobe Reader.

    I am having trouble establishing file association between .PDF files and Adobe Reader.  When I click on a .PDF file, Adobe Reader does not open the file.  I installed Adobe Reader on a Lenovo G480 laptop using Windows 8.  When I attempted to open a file called I believe G480_user_guide.PDF, a file called something like Nitro_PDF opened.  When I right clicked G480_user_guide.PDF and chose Open With, I found that Nitro_PDF was the default program for opening the file.  I tried to change to another program but found that Adobe Reader was not listed.  I chose the option for searching the computer for a file to open.  I found the folder Adobe in Program Files x64 but I was not able to find an executable.  Where is the Adobe Reader executable or what other method can I use for establishing file association between .PDF files and Adobe Reader.

    Yes, I have now learned how to make a search with the Google search engine.  I am gradually learning how to use my new Lenovo laptop computer with Windows 8.  I learned yesterday that I can make a search with the Google search engine if I enter the search query in the address bar of the Google Chrome browser.  I think it was the Bing search engine that gave me the sites advertising Adobe Reader download but actually provided the download of a reader other than Adobe.
    In my opinion, Windows 8 is significantly different from Windows 7 and that it has hazards and pitfalls.
    I thank all of those who have replied to the initial inquiry.

  • Having trouble installing Adobe Reader 8, know it's outdated, job requires it. System is Windows 7

    having trouble installing Adobe Reader 8, know it's outdated, job requires it. System is Windows 7 Home Premium. Thank you.

    You may see if there are solutions in this old thread: http://forums.adobe.com/message/3063830
    Although that combination isn't supported, many people have made it work.
    Why would a job require Reader 8? All older files are compatible with newer versions. Or at least they should be.

  • I'm using the latest photoshop cc 2014 with most updated camera raw... i am having A LOT/REPEATED trouble getting files to "synch" with corrections, no matter what i options i select (i.e. "everything")... WTH is wrong with me/my computer/adobe?! help. fa

    I'm using the latest photoshop cc 2014 with most updated camera raw... i am having A LOT/REPEATED trouble getting files to "synch" with corrections, no matter what i options i select (i.e. "everything")... WTH is wrong with me/my computer/adobe?! help. fast. please

    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Having trouble opening files in CS4

    I am having a color management nightmare and that has lead to my trouble opening files, so I'll explain that color management part first.
    I use Xrite Eye One Display Two as a calibration system and have recently bought a new Hewlet Packard 25 inch LCD monitor. Anyway, I am not seeing the same color outside of photoshop CS4 ext. that I see in photoshop CS4 ext. When I post a picture to the web, the color changes. I did read a post about this a few threads down, but my problem goes one step further. I changed some settings in the Save for Web section of photoshop and now I can't even open files from Bridge or directly from inside photoshop. Can anyone help me get back to just having problems with color? lol
    I am quite the novice when it comes to certain things in adobe photoshop CS4, so thanks for any help or advice you could give me.

    Gotta love the way HP throws out that "72% Color Gamut" spec (e.g., on this page) without actually saying what color profile or standard it's the gamut of.
    Color management is not something that can be easily explained in a paragraph.  Since you're calibrating your monitor it is kind of important for you to understand what it's all about - and such understanding is possible with just a little effort and reading time.  There are a lot of color management overviews online that can be turned up with a Google search.
    No file showing up without any error message seems kind of weird.  Are you using Windowed view or Tabbed view?  I ask because I'm wondering if somehow the document is opening up off-screen.  Do the entries in the Filter menu become active after such an open?
    Does a document show up if you switch the Open Documents as Tabs setting in Edit - Preferences - Interface?
    Have you installed any plug-ins that are supposed to provide access to any file types not available normally in Photoshop?
    -Noel

  • Having trouble opening files

    Can somone help me having trouble opening files with my Ipad

    I started having the exact same problem yesterday. It has happened to me a little less than 2 years ago on this same machine (which was very new at the time). I was hoping to come here and find an easier solution than I resorted to in the past. Before I had to completely reformat my computer to get it to work properly again.
    For me, the first time this problem happened was when I was working on a job that is stored on our company server. The server went down while the file was open and I was kicked off and everything locked up. When I tried to get out of the file nothing happened and I had to force quit. When it got back up, I logged back onto the server and everything seemed fine until trying to open, save as or place a file. Then I see what you see, open a folder and rather than going inside the folder, I get the turn down arrow or I just see the same list of folders and cannot get into the final folder where the art resides that I wish to place (or attach in an email, etc.)
    I don't know how it happened yesterday. It could have actually happened on Friday night. Our company runs 3 shifts and it may have happened on 2nd shift Friday night or on 3rd shift Sunday night / Monday morning. I discovered it yesterday afternoon.
    If anyone has a better solution than reformatting, that would be GREAT! I have done the disk utility checking and fixing permissions and that didn't work the first time or today either. Thanks for any info!

  • I am having trouble moving files from iPhoto to a thumb drive.  Sometimes I can move 20 photos next time I can only move 2 photos or 0---this is during the same session.  I also have trouble downloading photos to the internet.  Can someone please help?

    I am having trouble moving files from iphoto to a thumb drive.  During the same session sometime I can move 10 photos at a time, the next time I can only move one photo and sometime no photos will move.  I also have trouble downloading photos to the internet.  I was using a MacBook Pro and had no problems like this.  I then upgraded to the MacBook Pro with Retina Vision and this is the computer I am having problems with.  Can anyone please give me a suggestion in how to fix this problem. THANK YOU.

    iPhoto problems should be posted in their forums.
    I also have trouble downloading photos to the internet.
    Needs clarification.  You upload from your computer to the internet & download from a website/internet to your computer.  So which are you trying to do?  Either way, sounds like a browser issue.  You need to post in the forum of whichever browser you are using.

  • I am having trouble opening Adobe Reader after I install it in my Safari.

    I am having trouble opening Adobe Reader after I install it in my Safari. I have installed reader about 10 times now and it says I can use it now, but when I try to open a file it tells me I need to launch Reader and Agree to terms. I really need to use it now for school. Please help. Thank you, Heather

    You need to open Reader outside of Safari Start>All programs and accept the agreement.

Maybe you are looking for

  • Queues are not processed properly in BPM

    Hi all , In BPM , the inbound queues of the process engine are not processed properly. Several message are sent to the process and the message queued in the QRFC queue. How to process those messages so that process instance gets created ? Kind regard

  • Missing Thumbnails in Organizer Importing Function

    I recently upgraded my my operating system from Windows XP to Vista.  When I used the import function in Elements Organizer (with XP) I could preview the thumbnails and select the desired images on the camera or compact flash card.  Now that I have m

  • How to separate payment method by level of payment amount

    Hi    Please help me, I want to set configuration for transaction F110, I have two payment method (C:Check, T:Transfer). At each vendor If payment amount less than 2 million --> T, if amount greater than 2 million --> C method, How I can do it? Thank

  • RSNASTED - Functional Specifications

    Hi Experts, I would like to know if any document(s) is/are available on program RSNASTED that is used to generate EDI Invoices for Customers. I am looking for a document on how this program works, what data gets picked from where and such related inf

  • JS CS5.5-Moving Selected Objects-Please Help!!

    Hello, I have a scritpt that will apply a certain object style to the selected items in the document. I am trying to add a "move" to this scirpt. I would like every item selected in the document to move down .125 inches. I know this is much simpler t