Reading in from file

Hi, I've been looking at some resources online but cant seem to understand it very well.
I have been given partially completed code from my lecturer, and i have to complete this code.
I'm not looking for solutions but if you would be so kind to either explain or point me into the direction of helpfull resources i would be very gratefull!
Heres my partially completed code:
       public void load(File file){
            String line;
            String[] fields;
            try {
                BufferedReader in = new BufferedReader(new FileReader(file));
                line = in.readLine();
                this.setName(line);
                line = in.readLine();
                fields = line.split(",");
                HeadOfSchool h = new HeadOfSchool(fields[0], fields[1], fields[2],
                    Integer.parseInt(fields[3]), Integer.parseInt(fields[4]));
                // COMPLETE THE READING IN FROM FILE
                // ADD YOUR CODE HERE
                in.close();
            } catch (IOException e) {
                    // ADD YOUR OWN CODE HERE
    }Here is the contents of the file which is being read in:
The file which stores information about the school is as shown below
School of Computing
Prof Shirley Campbell,Aberdeen,female,45,45000
8
Dr John Smith,Aberdeen,male,40,28000
Dr Joan Simpson,Aberdeen,female,30,27500
Mr Tony Orlando,Banchory,male,40,27500
Dr Craig Stuart,Aberdeen,male,38,18500
Dr Moira Cables,Aberdeen,female,35,22500
Dr William Green,Aberdeen,male,38,35500
Mr Henry Brown,Aberdeen,male,37,27265
Ms Jill Blossom,Aberdeen,female,48,30000
Course UG1,4
Alan Smith,Aberdeen,male,35,A
Mary Grant,Banchory,female,25,B
Joe Bloggs,Aberdeen,male,42,A
Jack Hawkins,Stonehaven,male,30,C
Course UG2,5
Susan Clark,Aberdeen,female,18,C
Carol Roberts,Murcar,female,32,B
Roy Rogers,Ellon,male,37,B
Melanie Sykes,Murcar,female,22,A
Colin Firth,Aberdeen,male,27,A
Course UG3,3
Cindy Lauper,Aberdeen,female,27,A
Jim Bowen,Banchory,male,47,C
Andy Townsend,Arbroath,male,35,BFormat of the file:
The format if the file is
Name of school
Details of the Head of School
Number of Lecturers
List of Lecturers
Name of course1, number of students
List of Students
Name of course2, number of students
List of Students
Name of course2, number of students
List of Students
Name of course3, number of students
List of StudentsSorry if i havent supplied you with relevant details, just let me know if theres anything else i need to let you guys know
Thanks

The code given to you as an example demonstrates how to open the file, read a line of data from it, and split that line into parts.
You are given the format of the file, and example data.
So - given that you know how to read a line of data from the file and split it into parts, and given that you know what the lines of the file look like - can you write out in your native language what you need to do, using "read a line", "split the line into pieces", "use the nth piece" operators, to process the file? If you can, then do, and convert that to Java. If you can't, then you need to back up and understand your problem better, then try to write out your solution in your native language.
If you run into any specific, technical problems come back and ask away
Good Luck
Lee

Similar Messages

  • Bug: Keywords behave incorrectly after "Read Metadata from File"

    (Happens in LR3.4 RC and probably also in previous versions... but I am not sure if it happened in LR2)
    The problem seems tro be somthing like de-sync of database status and what we see on the screen.
    1) Let's say we have a photo with keyword "abc"
    2) Click in the Keyword List on the arrow around the "abc" keyword to show only photos with this keyword (single one), leave the filter on this settings
    2) Save Metadata to File
    3) Edit XMP in an external application, add new keyword "def"
    4) Read Metadate from File
    5) Now what happens is: The photos disappers from the screen as if it lost the "abc" keyword (weird), but if you look at the Keyword List, the "abc" keyword has still 1 photo attached to it. Also, if you release the filter and find the photo, it clearly has the "abc" and "def" keywords in the Keywording panel. And you can search for this keyword in the text filter (works correctly), but if you click on the arrow around the "abc" keyword, the photo is not shown.
    6) If you restart the Lightroom, it will work correctly again.
    I have an own application that is able to modify the XMP and the modifications may not be perfect, but in my opinion, this shouldn't happen when reading the metadata. If any developer is reading this, I can supply a file with original and changed metadata for debugging.
    It would be great it this could be resolved.
    Thanks!

    Please do report your find with the details you state (well done!) here: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    Thanks.........

  • Export with Table Splitting : ORA-01115: IO error reading block from file

    Hello,
    We are in perfroming the last dryrun of our CU&UC conversion.
    The are now in the process of exporting the ECC6 system (Oracle 10.2.0.4.0, HPUX ia64) using sapinst features, "table splitting preparation"
    When doing so, we are facing critical errors :
    Creating file /export_uni/sapinst_splitting/ora_query3_tmp3_1.sql.
    ERROR 2010-08-11 10:27:28.881
    CJS-00084  SQL statement or script failed. DIAGNOSIS: Error message: ORA-12801: error signaled in parallel query server P002
    ORA-01115: IO error reading block from file 90 (block # 16640)
    ORA-27072: File I/O error
    HPUX-ia64 Error: 22: Invalid argument
    Additional information: 4
    Additional information: 16640
    Additional information: -1
    ORA-01115: IO error reading block from file 90 (block # 16640)
    ORA-27072: File I/O error
    HPUX-ia64 Error: 22: Invalid argument
    ORA-06512: at "SAPR3.TABLE_SPLITTER", line 775
    ORA-06512: at line 1
    I have therefore perfmed a dbverify ; no corruption has been recorded.
    When trying to perfrom the EXPORT, without table splitting ; it works fine ...but the processing time is extremely long, as you can imagine. Any help would be highly appreciated.Regards.
    Raoul

    Thank you Stefan,
    Our HPUX Release seems to be indeed 11v3,
    [root@:/root]# uname -a
    HP-UX B.11.31 U ia64 2566039091 unlimited-user license
    I'll check the installation of the  patch and keep you informed
    Thank you
    Raoul
    Edited by: Raoul Shiro on Aug 11, 2010 11:57 AM

  • Reading data from file in EJB

    I would like to read data from files in EJBS (Stateless Session Bean I think). I've heard that the EJB sepcifications don't allow to use the java.io package to access the filesystem. How can I resolve this problem? Possible solutions I've thought of are:
    * Use a webserver to store the data
    * put the files in a jar and access them using the getResource() in the classloader class
    Could you comment on this plesae
    greetings

    The specification states:
    "An enterprise bean must not use the java.io package to attempt to access files and directories in the file system.
    The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC, to store data."
    From this I understand I cannot acces files directly, but it does not specifiy I can't use the java.io package at all. It specifically says not to use the java.io package to acces files and directories, they don't say anything about using the classes for other use.
    however, a litle lower the specification states:
    "The enterprise bean must not attempt to create a class loader; obtain the current class loader; set the context class loader; set security manager; create a new security manager; stop the JVM; or change the input, output, and error streams.
    These functions are reserved for the EJB Container. Allowing the enterprise bean to use these functions could compromise security and decrease the Container�s ability to properly manage the runtime environment."
    I'm not sure how to interpret this, but I believe this rule makes my solution invalid.
    Please comment on this,
    thanks

  • Failed to read PID from file /run/nginx.pid: Invalid argument

    Hi,
    tried to get an nginx server running to set up an owncloud environment.
    When starting the nginx server
      $  systemctl start nginx.service
    I get the message: "Failed to read PID from file /run/nginx.pid: Invalid argument"
    [root@klaus /etc/nginx]# systemctl status nginx
    nginx.service - A high performance web server and a reverse proxy server
    Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
    Active: active (running) since Sat 2013-10-12 17:50:46 CEST; 8min ago
    Process: 1823 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 1821 ExecStartPre=/usr/bin/nginx -t -q -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Main PID: 1825 (nginx)
    CGroup: /system.slice/nginx.service
    ├─1825 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on;
    └─1826 nginx: worker process
    Oct 12 17:50:46 klaus systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
    Oct 12 17:50:46 klaus systemd[1]: Started A high performance web server and a reverse proxy server.
    but /run/nginx.pid is readable:
    # cat /run/nginx.pid
    2058
    # ll /run/nginx.pid
    -rw-r--r-- 1 root root 4 Oct 12 17:39 /run/nginx.pid
    It seems nginx is runnung thought but in my browser I only get a blank page.
    Any help appreciated.
    Last edited by wombalton (2013-10-13 14:17:46)

    Actually it's the first time I tried to set up one.
    I Basically followed this guide [1] adopting it to arch.
    That's where i got my nginx.conf from. Taking the standard nginx.conf that comes by install and replacing the server part.
    After some searching I found the owncloud manual[2] with an example nginx.conf. Comparing that with my one I found some differences. Applying them works out fine.
    I get now the owncloud page.
    The systemd error  still ocurs, but I think it does not matter to run the server.
    Thanks for your help.
    [1] https://docs.google.com/file/d/0B0ZsTQd … ring&pli=1
    [2] http://doc.owncloud.org/server/5.0/admi … figuration
    EDIT:
    Just in case someone stumbles over this and tries to use the config:
    This one [3] really works
    [3] http://doc.owncloud.org/server/5.0/admi … thers.html
    Last edited by wombalton (2013-10-14 13:31:22)

  • Bug: "Read metadata from file"

    When I add GPS coordinates to a file (with the program Geotagger) and select "read metadata from file" to import the new metadata, a color adjustment badge appears on the thumbnail (even though I didn't adjust any colors). This only happens with files that have a cropping applied to them in Lightroom. If the file doesn't have a custom cropping the color adjustment badge doesn't appear. It happens with both JPG and CR2 files. Seams like a bug to me.
    I'm on a 24" iMac 2.8 with 4 GB and OSX 10.5.5 / Lightroom 2.1

    It also happens with DNG. Anyway, I don't think it has anything to do with the GPS, but the issue has been around right back through version 1.x Try the following:
    1. Select an image that has no crops or develop adjustments
    2. Switch to Develop module
    3. Apply a crop
    4. Save metadata to file (Cmd+S)
    5. Read metadata back from file (Metadata menu - "Read Metadata from file"
    Please report what happens?
    At my end the Crop badge remains but a Develop Adjustment badge also appears - IMO it shouldn't, but as stated above it has for a VERY long time. I'll bug it again and see what happens.

  • Batch read metadata from file

    Hi Everybody,
    I wonder if Lightroom 3 offers a function that lets me read metadata from file for multiple images in a batch process. The reason is that I have changed the GPS information for quite a couple of my pics using the Geoencoding Support pluging from Jeffrey Friedl and let it write back into the DNG-file. Since I also flushed the shadow data I can't see any GPS information in my metadata table in Lightrrom even though the data are present in the DNG. Now the real question is: Is there a better way to get my GPS data into Lightroom than emptying the Library and reimport all of my pics?
    Oh, and before I forget it: Yes, I have searched this forum - and a couple of others as well - and I found stuff about batch processing date/time information. However, the method presented there apparently does not apply to my problem.
    Thanks for any information.
    Have a nice day,
    f.

    In Library Module, select Grid Mode. Select all images you wish to read metadata from. Go to Metadata>Read Metadata from Files
    Similarly, you can edit time for time zone/ AM-PM issues, etc by going to Metadata>Edit Capture Time

  • Reading Metadata From File Resets the Setting

    I am using Lightroom 4 on MAC OS X Yosemite. I have done some editing on a picture in DNG format and then clicked "Save Metadata to File".  I checked the XMP file with textedit and found that the change is indeed saved. But when I click "Read Metadata From File", it resets the pictures before any editing. Please, I need help to fix this problem.

    jinsheng wrote:
    I have done some editing on a picture in DNG format and then clicked "Save Metadata to File".  I checked the XMP file with textedit and found that the change is indeed saved.
    I'm confused - I'm pretty-sure Lightroom 4 will not save changes to an xmp file (even if DNG is read-only, unlike Bridge) - it embeds the metadata in the DNG file. Did you mean you edited the DNG file with a text editor? Anyway, if you do have a .xmp sidecars to your DNG, I recommend deleting them, or renaming them (until you figure out what's going on anyway), then retry - any difference?
    PS - last I checked, Lr will generate an error when saving metadata if DNG is read-only, but since you're having a strange problem, I'd definitely make sure they are not read-only.
    Note: Lr WILL read metadata from an xmp sidecar, *iff* it seems newer than what is embedded. So, IF you have xmp sidecars that have a recent modification date, or *maybe* (I don't really know) if Lr was NOT able to successfully embed metadata into your DNG, it could be reading some incompatible metadata from the xmp sidecar - thus the reason to get it out of the way to test..

  • Can't read frame from file

    We use proxies in our work flow, pre-rendering certain comps before rendering out the final project. For the most part this works fine, but occasionally we'll get an error that reads: "Error (4) reading frame from file." It's always the same comp but it doesn't cause the problem in every project.
    We use the quicktime codec with Tiff compression. Could it be a memory issue? Any help would be greatly appreciated. The error always pops up at the most inconvenient time -- of course.
    Thanks,
    Julian

    Well, if it's always the same file, then most likely one of the source footages is really damaged. The error not occuring every time mustn't mean anything. If the element in question is not visible at the given frame or AE doesn't do anything with it because it isn't required, naturally the error would not occur. I'm afraid the only way to track this down is to selectively disable/ remove the sources from the comps in question and render some test clips. Perhaps it would also help to check all the files used in the project in a "neutral" app such as external image and video viewers (XnView, VLC, MediaPlayer Classic...)
    Mylenium

  • Read metadata from file cancel modifications !

    Hi,
    I use Lightroom 1.1 in french. I made some photo (in raw but in jpeg the result is the same) and import them in Lightroom with conversion in DNG. In Lightroom, in develop module, I crop, change contrast and som others.
    After that, I geotag my DNG files with HoudahGeo. HoudahGeo write geotag in the file. So back in Lightroom, I make a 'Read metadata from file' ('Lire les métadonnées depuis les fichiers' in french) for having geotag in Lightroom.
    Geotag are now in Lightoom, nice, but in develop history, I have a new line 'Rénitialiser les paramètres' !!! So I can't see all my modifications... Is it normal ?
    Thank you
    PS: Sorry for my english...

    I think you should test this with one or two pictures - import/convert, save metadata to file, geotag, read metadata. Also try import/convert, make small adjustment, save metadata to file, geotag, read metadata. In iView I often write metadata to DNG's that have been adjusted, then read the metadata in Lightroom - sometimes I add more data in iView and do more adjustments.
    I have seen the problem you describe, but it has been with raw files which I have adjusted in Lightroom but haven't saved out the metadata. I have then created an xmp sidecar in iView, and read the metadata in LR. So the sidecar had no ACR/LR instructions. The result was that my adjustments were wiped out. What I suspect is that something similar is happening with your DNGs - that conversion creates them but doesn't write the ACR/LR fields.
    So try a few alternative sequences.
    John

  • Feature Request: save metadata to file, and read metadata from file.

    Please have function to save metadata to file, and read metadata from file.
    This would allow us to write cross-platform plugins that can assure data is up-to-date in the xmp, or modify xmp and have it reinstated in the catalog.
    This would go nicely with the ability to save xmp for virtual copies, dng, and rgb formats.

    Perhaps someone with direct experience with publishing to Smugmug will chime in.  Short of that, some thoughts on your issues:
    Should I not bother to "Save Metadata to File", this seems to be what is messing up the SmugMug publish service?
    I very much doubt that it is messing up the publishing.  What gets saved to the file from the catalog is independent of what gets exported.  Saving metadata to the file is generally a good practice (in case you screw up your catalog backups).  Many, perhaps most, users set the preference Catalog Settings > Automatically Write Changes Into XMP.
    I would have expected it to behave like an export which would write synonyms, exclude keywords that should be excluded, etc, which seems to work ok in point 6 above.
    Yes, that's a reasonable expectation.
    You may have done this already, but double-check: Right-click the Smugmug publishing service in the left-hand column of the Library, select Edit Settings, and in the Metadata section verify that you have Include: All Metadata set.
    Did you download the Smugmug plugin from Smugmug? You might try this Smugmug plugin instead -- the author designed the publishing architecture of LR and has an excellent reputation. 
    Are the publish services more effort than they are worth? So I get SmugMug to work, what happens when I try Flickr?
    I think many users find the publishing services are generally worthwhile.  I publish regularly to Flickr (using the built-in Flickr plugin, which isn't completely reliable) and the Zenfolio plugin from Friedl. 

  • Replace read character from file

    HI,
    I have updated my labview 2014 and have a load and save function wich not working on the new version.
    It says that the read character from file is not supported any more.
    How to i fix it to run in labview 2014?
    Attachments:
    Load.png ‏62 KB
    Save.png ‏365 KB

    Bob_Schor wrote:
    Please do not attach tiny pictures of your VIs (I can't see them clearly).  Instead, attach the VIs, themselves -- this lets us open them in LabVIEW, see if there are any broken arrows, read the error messages, and actually try your code (any test any fix we might suggest).  Help us to help you.
    Do you know about Snippets?  This is what looks like a .PNG file, but can be dropped in a LabVIEW Block Diagram to become executable code.  Find it on the Edit menu of the Block Diagram.
    Bob Schor
    HI,
    OK, I have now attach my VIs.
    //Ronny
    Attachments:
    Save.vi ‏11 KB
    Load.vi ‏11 KB

  • I want to read lines from file, count it and extract numbers from a first line.

    i must do un loop?

    HI,
    i try to explain how to use to LABVIEW TOOLS...
    1. USE a for next loop
    2. here you must open the file with the VI. read lines from file.
    you can choos how many lines you read at same time.
    3. the string you can convert into an number.
    4. in the loop is the literal counter... this is you line couter....
    iun schrieb:
    > i must do un loop?

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

  • Reading integers from file problem...

    I managed to read integers from a file but only the ones from the first line. I can't somehow read the remaining lines.
    The format is...
    33 212 3111 12 1
    1
    123
    2 3 4
    I know that the first while loop pretty much does nothing...
    Any help is appreciated :)
    import java.util.*;
    import java.io.*;
    public class TokenTest {
          public static void main(String[] args) throws Exception {
                BufferedReader in = new BufferedReader(new FileReader("numbers.txt"));
                String line = in.readLine();
                StringTokenizer st = new StringTokenizer(line);
                while (in.readLine() != null) {
                      while (st.hasMoreTokens()) {
                            String s = st.nextToken();
                            int j = Integer.parseInt(s);
                            System.out.print(j + " ");
    }

    Ok i kind of done it. For the input...
    0 56 3
    23 6 10 12
    3 2 4
    1
    It returns 23 6 10 12 3 2 4 1. Basically all the numbers except for the first line.
    import java.util.*;
    import java.io.*;
    public class TokenTest {
          public static void main(String[] args) throws Exception {
                BufferedReader in = new BufferedReader(new FileReader("numbers.txt"));
                String line = in.readLine();
                while ((line = in.readLine()) != null) {
                      StringTokenizer st = new StringTokenizer(line);
                      while (st.hasMoreTokens()) {
                            String s = st.nextToken();
                            int j = Integer.parseInt(s);
                            System.out.print(j + " ");
    }

Maybe you are looking for

  • Help ...how to get the file size on a server

    Hi.I use this code to parse a file that is on a server. The question is: how can i get the file size (bytes size)? Thanks. //Open the file for reading: URL u = new URL(entry); InputStream inputXML = u.openStream(); //Build document: DocumentBuilder b

  • FCP 7 Crashes after install of ATI Radeon HD 5770

    FCP 7.0 MacPro1,1 Mac OS X 10.5.8 Darwin 9.8.0 (2) Dual-Core Intel Xeon 3 GHz processors (Memory:          4 GB) (2) 500GB internal HD's (2)  500 GB external HD's  Graphics Card: ATI Radeon HD 5770   Type:          Display   Bus:          PCIe   Slot

  • MDM Adapter dynamic configuration

    Hi All, The scenario is, PI picks up a file from ECC using sender File adapter and sends it to different MDM ports using the Receiver MDM adapter. The only difference in the different receiver MDM communication channels sending the data to different

  • Memory use imac 8.1 core 2 duo 32 bit.

    Hello I have an imac 8.1 at work that is currently on 10.6.7 with 4gb of ram. (First time actually work working with macs) I need to use Vmware fushion to run a program for a co worker. (win 7) However as this mac is older it's bogging it down. I hav

  • How to open a port in RV325?

    Hey guys, I'm looking for a way to open a port (port 43 - whois) in RV325, so I can check if domains are taken for my customers and I don't want to use an external service for this. I tried using the GUI, telnet and SSH, but I couldn't find it in the