Reading an int from a particular location in a file

Hi, I've seen other topics about reading ints from files/strings etc, but I don't think I've found one the same as this.
I have an input file "maxSolution.sol" that contains an int that I need to use in my program
c Parsing PB file...
c Converting 0 PB-constraints to clauses...
c -- Unit propagations: (none)
c -- Detecting intervals from adjacent constraints: (none)
c -- Clauses(.)/Splits(s): (none)
c ==================================[MINISAT+]==================================
c | Conflicts | Original | Learnt | Progress |
c | | Clauses Literals | Max Clauses Literals LPC | |
c ==============================================================================
c | 0 | 0 0 | 0 0 0 nan | 0.000 % |
c ==============================================================================
c Found solution: -1
c Optimal solution: -1
s OPTIMUM FOUND
v x0001 -x0101 -x0200 -x0201 -x0800
c _______________________________________________________________________________
c
c restarts : 1
c conflicts : 0 (nan /sec)
c decisions : 2 (inf /sec)
c propagations : 0 (nan /sec)
c inspects : 0 (nan /sec)
c CPU time : 0 s
c _______________________________________________________________________________
The int that I require is the one that appears after "Optimal Solution: ". I actually require the absolute value of this, so I have tried the following
public int maxInputReader(String s) throws IOException
String optimal = "Optimal Solution:";
int mines = 0;
File input = new File(s);
Scanner filein = new Scanner(input);
while(filein.hasNext())
if(filein.next() == optimal)
mines = Math.abs(Integer.parseInt(filein.next()));
return mines;
However, when I run this method, it returns 0, the initial value for the int mines, could anyone give me a hand as to what I am doing wrong?

much better:
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExpTest {
     public RegExpTest(){
          try {
             // Create matcher on file
             Pattern pattern = Pattern.compile("Optimal solution:\\s*(\\-)\\d");
             Matcher matcher = pattern.matcher(fromFile("your_file_path_here.txt"));
             // Find all matches
             while (matcher.find()) {
                 // Get the matching string
                 String match = matcher.group();
                 System.out.println("Line : "+match);
                 int i = Integer.parseInt(match.substring(match.indexOf(':')+1).trim());
                 System.out.println("Number: "+i);
         } catch (IOException e) {
              e.printStackTrace();
     //Converts the contents of a file into a CharSequence
    // suitable for use by the regex package.
    public CharSequence fromFile(String filename) throws IOException {
        FileInputStream fis = new FileInputStream(filename);
        FileChannel fc = fis.getChannel();
        // Create a read-only CharBuffer on the file
        ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int)fc.size());
        CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf);
        return cbuf;
    public static void main(String[] args) {
          new RegExpTest();
}

Similar Messages

  • How to read from a certain location is a file?

    hi! i am new to programing and i have a problems abt reading from a file. i have write the following to a file using FmtFile :
    10 (a numbers)
    name,phone,product (some strings)
    9 (a numbers)
    when i user ScanFile to read the second number(9 in the above example), i got a wrong value. the command i use is:
    ScanFile (filehandle, "%d", &number1);
    ScanFile (filehandle, "%s[t44]%s[t44]%s",name, phone product);
    ScanFile (filehandle, "%d", &number2);
    number1 and number 2 are integers and name, phone and product are char arrays.
    can anyone tell me where have i gone wrong? or maybe someone can tell me how can i read the 2nd number without reading the 1st number
    and the strings.

    Let's look at your file: if I correctly interpret your question, one row in it should like like this:
    10,name,phone,product,9
    In this case you could use the following formatting string to read all data from the string:
    "%d[x]%s[xt44]%s[xt44]%s[xt44]%d"
    [x] means to discard terminator, in order to read from strings, for example, "name" and not "name,". It's important in this case to put ALL field separators.
    Maybe your problem is that in the file you don't have separators between strings and numbers: in this case the last "%s" should read the '9' inside the last string and the subsequent "%d" matches with incorrect area in the file (end-of-line or next row).
    Hope this help
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Saving PDF From in particular location

    Hi all,
    I am having one query i have a requirement that the form that is initiated should be stored in particular location.
    eg: i have initiated the form with input ABC in one filed and my requirement is that after final approval the file should create a folder ABC and PDF should stored  in that folder like abc.pdf
    C:\\ABC\ABC.pdf
    please let me know how can i do in the work flow.
    thanks in advance
    Sekhar

    The following operation will do that.
    Service Name: File Utilities
    Operation Name: Write Document
    Note: The file cannot be written on the client PC.
    Nith

  • Streaming from a specific location within a file

    Hi everybody,
    I'm a newbie here so please be patient if this is a trivial
    question.
    What I need to know is the following: can I start streaming a
    video/audio file from a specific location (like a timestamp) with
    Flash Media Server?
    More precisely, the idea is this: I want Flash Media Server
    to establish a connection with another server (remote server) to
    receive some information like a file name and a time stamp. After
    this I want Flash Media Server to start streaming (to a simple
    client, like always) that file from that specific moment indicated
    in the "packet" it received from the other server. Can this be
    done? Is it hard?
    Thank you so much,
    Francesco.

    DarrylBurke wrote:
    sabre150 wrote:
    JosAH wrote:
    And who's the slowest old sod again? ;-)
    kind regards,
    JosMe! I had not even got round to answering this!Humph. I only just read it.
    dbPlease stand in the corner next to Sabre please.
    kind regards,
    Jos (<--- speedy ;-)

  • Add node at particular location in XML file

    I'd like to add an item to a particular location in an XML file.  Location of parent node is given by string variable "itemtoaddto" and the XML file is given by "myXML":
    function TraverseXMLfile(itemtoaddto,myXML): void {
        var AttributeList:XMLList = myXML.attributes() + myXML.*.attributes() + myXML.*.*.attributes();
         for each (var labelname:XML in AttributeList) {
          if(labelname == itemtoaddto){
            trace (labelname + "match found!!!!!");
            myXML.*.labelname.appendChild(<SON name="Will" bday="01/15" />);
    In the above code, the parent item is being found in fact it's printing the "match found!!!!!" message.  However, the line
           myXML.*.labelname.appendChild(<SON name="Will" bday="01/15" />);
    is giving the following error:
         TypeError: Error #1086: The appendChild method only works on lists containing one item.
    Can someone help please? thanks.

    var myXML:XML = <product>
                                <subAssembly label="Sub1">&#8232;           
                                    <part label="Part1_1"/>&#8232;           
                                    <part label="Part1_2"/>&#8232;           
                                    <part label="Part1_3"/>&#8232;           
                                    <part label="Part1_4"/>&#8232;       
                                </subAssembly>&#8232;       
                                <subAssembly label="Sub2">&#8232;           
                                    <part label="Part2_1">&#8232;               
                                        <feature label="Feature2_1_1"/>&#8232;               
                                        <feature label="Feature2_1_2"/>&#8232;           
                                    </part>&#8232;           
                                    <part label="Part2_2">&#8232;               
                                        <feature label="Feature2_2_1"/>&#8232;               
                                        <feature label="Feature2_2_2"/>&#8232;           
                                    </part>&#8232;       
                                </subAssembly>&#8232;       
                                <subAssembly label="Sub3"> &#8232;           
                                    <part label="Part3_1">&#8232;               
                                        <feature label="Feature3_1_1"/>&#8232;               
                                        <feature label="Feature3_1_2"/>&#8232;           
                                    </part>&#8232;       
                                </subAssembly>&#8232;
                            </product>;
    myXML.subAssembly.(@label == "Sub1")[0].insertChildAfter(myXML.subAssembly.(@label == "Sub1")[0].part[myXML.subAssembly.(@label == "Sub1").part.length() - 1], <part label="Part1_5"/>);
    trace(myXML);
    This traces:
    <product>       
      <subAssembly label="Sub1">          
        <part label="Part1_1"/>      
        <part label="Part1_2"/>
        <part label="Part1_3"/> 
        <part label="Part1_4"/>
        <part label="Part1_5"/>
      </subAssembly>
      <subAssembly label="Sub2">
        <part label="Part2_1">        
          <feature label="Feature2_1_1"/>      
          <feature label="Feature2_1_2"/>    
        </part>  
        <part label="Part2_2">      
          <feature label="Feature2_2_1"/>      
          <feature label="Feature2_2_2"/>   
        </part>
      </subAssembly>
      <subAssembly label="Sub3">
        <part label="Part3_1">       
          <feature label="Feature3_1_1"/>     
          <feature label="Feature3_1_2"/>
        </part>
      </subAssembly>
    </product>

  • Reading A String at a random location in a file

    Question:
    Given a file of English words (a dictionary file I guess�), delimited by commas, I want to know if it is possible to write a java program that can read a random word from the dictionary file and store it into a String.
    If this is possible, I would like to know how to possibly implement such program.

    Given a file of English words (a dictionary file I
    guess�), delimited by commas, I want to know if it
    is possible to write a java program that can read a
    random word from the dictionary file and store it
    into a String.One way is to scan the word file once and store the starting position of each word in a new file. Say you get N entries. To read a word randomly you first generate a random integer between 0 and N-1. You use that number to look up the corresponding word position in the first file. Using that you finally look up the actual word in the second file. (To speed things up if the first file isn't too big you can keep it in memory as an integer array).
    The above procedure will give each word an equal chance of being selected.

  • To read & save data from serial port (write to .csv file), and plot data as waveform

    Hi,
    I've been stuck with this problem for weeks and really need some help. I've been searching a lot but I can't find a proper solution.
    I am trying to use Labview to plot and display some parameters of a data acquisition system for a project.
    The data acquisition system is connected to a computer via serial connection through COM 1 port.
    The data acquisition system sends a serial stream of data (ASCII string with baud rate 19200), as shown below (from HyperTerminal),
    01:00:26,933.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    01:00:27,931.54,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    The serial data stream consists of a time stamp (as 1st data), followed by 16 individual channel data, separated by comma "," and each stream ending in return "\n". Each value of the data ranges from 1 to 6 digits (value of -5000 to 15000).
     I have no problem reading this values correctly using HyperTerminal, but I have problem to plot and display individual parameters of this serial string in Labview. I want to save the entire data in  a “.csv” file corresponding to all the 16 channels with time stamp and plot each individual channel parameter in a graph with time on X-axis.
    I am relatively new to Labview hope I can learn a lot from your help.
     Thank you

    Thank you Dennis.........
    Now I had modified the program incorporating1D array for gauge display.....but currently I have a new problem. The program is running updating the file, waveform graph and Gauge very slowly. Approximately once in every 15 seconds 16 data streams are getting updated in a bunch with gauge sticking to the last value rather than indicating real time value.
    eg.
    12:33:41,-3728.78,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:42,-3730.47,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:43,-3729.81,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:44,-3733.80,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:45,-3733.57,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:46,-3729.27,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:47,-3725.97,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:48,-3730.14,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:49,-3733.20,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:50,-3733.60,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:51,-3732.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:52,-3734.51,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:53,-3728.07,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:54,-3732.54,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:55,-3732.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    12:33:56,-3731.58,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
    gets updated in a bunch after 15 seconds, rather than in every second. I thought the problem is with while loop but, i realised there is no delay associated with it..... Can u kindly help me in modifing the program so as it can update the waveform, file data and gauge in real time? (I have attached the modified VI file "suitcase new.vi" and the data gathered after executing the same as in "Trail.txt".)
    Thank You,
    Rahul
    Attachments:
    trail.txt ‏85 KB
    suitcase new.vi ‏44 KB

  • I am trying to read a document from a bank and the pdf file will not open for me to read it.

    I have downloaded and installed acrobat reader xl and I still can not read pdfs for certain places why is this?  I am using google chrome as my default browser.  I went to the same banking website using explorer and the pdf opened without a hitch.  Why is this?

    Because Chrome uses its own PDF viewer; you should use the Adobe Reader plugin on Chrome to view online PDF docs correctly.

  • Reading Files from an FTP location based on Timestamp

    Hi,
    I have a requirement of reading files from an FTP location. The files should be read in the order they were saved in the folder. Can someone tell me how to solve this?
    Thanks,
    Ravi

    Hi Arik,
    Thanks for your reply. I tried doing what u said, but it isn't working. My requirement is to List the files in the folder using FTP adapter and get the file name with the least file stamp from the FTP adapter and pass the FileName dynamically to another FTP adapter which reads the file based on the FileName. When i tested after including the property (for listing the files) you mentioned, it is giving the following error (copied from flow trace):
    <messages>
    <input>
    <Invoke_getFileListFTP_FileListing_InputVariable>
    <part name="Empty" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <empty xmlns="http://xmlns.oracle.com/pcbpel/adapter/ftp/APP_SequentialFileTransfer/PRJ_SequentialFileTransfer/WS_GetFileList_FTP"/>
    </part>
    </Invoke_getFileListFTP_FileListing_InputVariable>
    </input>
    <fault>
    <bpelFault>
    <faultType>0</faultType>
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="summary">
    <summary>Exception occured when binding was invoked. Exception occured
    during invocation of JCA binding: "JCA Binding execute of
    Reference operation 'FileListing' failed due to: Exception
    occured when binding was invoked. Exception occured during
    invocation of JCA binding: "Could not instantiate
    InteractionSpec
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec due
    to: Cannot set JCA WSDL Property. Error while setting JCA
    WSDL Property. Property setListSorter is not defined for
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec Please
    verify the spelling of the property. ". The invoked JCA
    adapter raised a resource exception. Please examine the above
    error message carefully to determine a resolution. ". The
    invoked JCA adapter raised a resource exception. Please
    examine the above error message carefully to determine a
    resolution.</summary>
    </part>
    <part name="detail">
    <detail>Cannot set JCA WSDL Property. Error while setting JCA WSDL
    Property. Property setListSorter is not defined for
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec Please
    verify the spelling of the property.</detail>
    </part>
    <part name="code">
    <code>null</code>
    </part>
    </bindingFault>
    </bpelFault>
    </fault>
    <faultType>
    <message>0</message>
    </faultType>
    </messages>
    Thanks,
    Ravi
    Edited by: Ravi Santosh on Apr 24, 2012 11:02 PM

  • Reading JSON data from a URL

    Hi all,
    I have a requirement of reading JSON data from a particular URL and using one of the value to set one property in iView. I need some info on how to get JSON data from a URL and extracting attribute's value from it.
    What are the APIs that can be used for this?Can anyone provide a solution/working example in Java for this?
    I am working on EP 7.3.

    Hi Tarun,
    JAXB should work for you. Take a look at this example:
    JAXB JSON Example | Examples Java Code Geeks
    Regards,
    Tobias

  • Problem concerning parsing int from .dat input

    The following program takes information form a ".dat" file, stores it and manipulates it. However, I am having a weird problem. Whenever I try to parse a n int from a certain point in the file (the end of a line) I keep getting thrown a java.lang.NumberFormatException. I understand why this would be thrown if I was sending it a wrong number, but, I am not. In fact the token before the last one sends it the same number and it parses fine. Here is the problem code;
    public void getPrice(Scanner scanner)
    while(scanner.hasNextLine())
    //puts into string the next scan token
    String s = scanner.next();
    //takes the scan toke above and puts it into an editable enviroment
    stringToken = new StringTokenizer(s, " ", false);
    while(stringToken.hasMoreTokens())
    //moves position within string in file by one
    position++;
    /*Starts data orignazation by reading from each perspective field
    * 1 = day
    * 2 = day of month
    * 3 = month
    * 4 = year
    if(position == 1)
    String dayFromFile = stringToken.nextToken();
    int dayNum = Integer.parseInt(dayFromFile);
    System.out.print(days[dayNum-1] +" ");
    else if(position == 2)
    System.out.print(stringToken.nextToken() + "/");
    else if(position == 3)
    System.out.print(stringToken.nextToken() + "/");
    else if(position == 4)
    System.out.print(stringToken.nextToken() +"\n");
    //if it is in [buy] area, it prints
    else if(position == 8)
    String buy = stringToken.nextToken();
    System.out.println("Buy: " +buy );
    currentBuyPrice = Integer.parseInt(buy);
    if(currentBuyPrice < 0)
    currentBuyPrice = 0;
    if(currentBuyPrice > buyPrice)
    buyPrice += currentBuyPrice;
    if(currentBuyPrice == buyPrice)
    buyPrice +=0;
    else
    buyPrice -= currentBuyPrice;
    //if it is in [sell] area, it prints, and resets the position to zero because line is over
    else if(position == 9)
    String sell = stringToken.nextToken();
    System.out.println("Sell: " +sell);
    **currentSellPrice = Integer.valueOf(sell).intValue();;
    if(currentSellPrice < 0)
    currentSellPrice = 0;
    else if(currentSellPrice > sellPrice)
    sellPrice += currentSellPrice;
    else if(currentSellPrice == sellPrice)
    sellPrice +=0;
    else
    sellPrice -= currentSellPrice;
    scanner.nextLine();
    position = 0;
    if(scanner.hasNextLine() == false)
    System.out.println("Net change of buy price: " buyPrice "\n Net change of sell price: " +sellPrice);
    //discards all other string areas
    else
    stringToken.nextToken();
    **The problem is here. The string prints as a perfect number, no spaces or anything. I thought it could be because the number was "-1" but I tried it without the "-" and it still threw the same thing. The really weird thing is that the buy code works fine, and it parses all ints I send it fine.
    EDIT:
    Here is how the .dat looks;
    1 5 15 2006 18 26 12 -1 -1
    1 5 15 2006 18 32 20 -1 -1
    1 5 15 2006 18 38 29 -1 -1
    It is the last "-1" that can not be parsed. I tried putting an excape character at the end so it looked;
    1 5 15 2006 18 26 12 -1 -1 &
    1 5 15 2006 18 32 20 -1 -1 &
    1 5 15 2006 18 38 29 -1 -1 &
    That did nothing.

    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JFrame implements ActionListener
    //GUI COMPONENTS
    JTextField input = new JTextField(20);
    JButton submit = new JButton("submit");
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = Calendar.getInstance();
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS;
    int monthS;
    int yearS;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    //toold for parsing and decoding input
    String inputS = null;
    String s = null;
    StringTokenizer stringToken = null;
    Scanner scanner;
    int position = 0;
                        public CSE()
                                    super("Test CSE");
                                    setDefaultCloseOperation(EXIT_ON_CLOSE);
                                    input.setBackground(new Color(0, 80, 250));
                                    submit.addActionListener(this);
                                    getContentPane().add(input, BorderLayout.SOUTH);
                                    getContentPane().add(submit, BorderLayout.NORTH);
                                    setSize(500, 500);
                                    setVisible(true);
                                        public void actionPerformed(ActionEvent e)
                                            getMonth();
                                            inputS = input.getText();
                                            FileReader newRead = null;
                                                    try {
                                                           newRead = new FileReader(monthS +"-" +day +"-" +year +"/" +inputS +".dat");
                                                           proceed = true;
                                                        catch(FileNotFoundException f)
                                                           System.out.println("File not found");
                                                           proceed = false;
                                          if(proceed)
                                          BufferedReader bufferedReader = new BufferedReader(newRead);
                                          scanner  = new Scanner(bufferedReader);
                                          scanner.useDelimiter("\n");
                                          getPrice(scanner);
                                    public void getPrice(Scanner scanner)
                                        while(scanner.hasNextLine())
                                            //puts into string the next scan token
                                            String s = scanner.next();
                                            //takes the scan toke above and puts it into an editable enviroment
                                            stringToken = new StringTokenizer(s, " ", false);
                                            while(stringToken.hasMoreTokens())
                                                             //moves position within string in file by one
                                                               position++;
                                                           /*Starts data orignazation by reading from each perspective field
                                                            * 1 = day
                                                            * 2 = day of month
                                                            * 3 = month
                                                            * 4 = year
                                                           if(position == 1)
                                                               String dayFromFile = stringToken.nextToken();
                                                                int dayNum = Integer.parseInt(dayFromFile);
                                                              System.out.print(days[dayNum-1] +" ");
                                                           else if(position == 2)
                                                               System.out.print(stringToken.nextToken() + "/");
                                                           else if(position == 3)
                                                               System.out.print(stringToken.nextToken() + "/");
                                                            else if(position == 4)
                                                                System.out.print(stringToken.nextToken() +"\n");
                                                           //if it is in [buy] area, it prints
                                                            else if(position == 8)
                                                                String buy = stringToken.nextToken();
                                                            System.out.println("Buy: " +buy );
                                                            currentBuyPrice = Integer.parseInt(buy);
                                                            if(currentBuyPrice < 0)
                                                                currentBuyPrice = 0;
                                                            if(currentBuyPrice > buyPrice)
                                                                     buyPrice += currentBuyPrice;
                                                            if(currentBuyPrice == buyPrice)
                                                                buyPrice +=0;
                                                               else
                                                                   buyPrice -= currentBuyPrice;
                                                            //if it is in [sell] area, it prints, and resets the position to zero because line is over
                                                            else if(position == 9)
                                                                String sell = stringToken.nextToken();
                                                              System.out.println("Sell: " + sell);
                                                              currentSellPrice = Integer.valueOf(sell).intValue();;
                                                               if(currentSellPrice < 0)
                                                                   currentSellPrice = 0;
                                                               else if(currentSellPrice > sellPrice)
                                                               sellPrice += currentSellPrice;
                                                                else if(currentSellPrice == sellPrice)
                                                                sellPrice +=0;
                                                               else
                                                               sellPrice -= currentSellPrice;
                                                                scanner.nextLine();
                                                                position = 0;
                                                               if(scanner.hasNextLine() == false)
                                                                System.out.println("Net change of buy price: " +buyPrice +"\n Net change of sell price: " +sellPrice);
                                                            //discards all other string areas
                                                            else
                                                            stringToken.nextToken();
                                public void getMonth()
                                    for(int x=0; x < monthCheck.length; x++)
                                        if(month == monthCheck[x])
                                              monthS = (x+1);
                                              x = monthCheck.length;
    public static void main(String [] args)
    CSE cs = new CSE();
    }Make a folder named whatever the current date is, and put a .dat file in there with this;
    1 5 15 2006 0 3  52 -1 -1
    1 5 15 2006 0 29 52 -1 -1
    1 5 15 2006 0 36  1 -1 -1
    1 5 15 2006 0 42  9 -1 -1
    1 5 15 2006 0 48 18 -1 -1
    1 5 15 2006 0 54 29 -1 -1
    1 5 15 2006 1 0  37 -1 -1
    1 5 15 2006 1 6 44 -1 -1
    1 5 15 2006 1 12 53 -1 -1
    1 5 15 2006 1 19 1 -1 -1
    1 5 15 2006 1 25 9 -1 -1
    1 5 15 2006 1 31 18 -1 -1
    1 5 15 2006 1 37 27 -1 -1
    1 5 15 2006 1 43 37 -1 -1
    1 5 15 2006 1 49 46 -1 -1
    1 5 15 2006 1 55 53 -1 -1
    1 5 15 2006 2 2 1 -1 -1
    1 5 15 2006 2 8 10 -1 -1
    1 5 15 2006 2 14 27 -1 -1
    1 5 15 2006 2 20 37 -1 -1
    1 5 15 2006 14 12 45 -1 -1
    1 5 15 2006 14 20 36 -1 -1
    1 5 15 2006 14 26 44 -1 -1
    1 5 15 2006 14 32 52 -1 -1
    1 5 15 2006 14 39 0 -1 -1
    1 5 15 2006 14 45 8 -1 -1
    1 5 15 2006 14 51 17 -1 -1
    1 5 15 2006 14 57 26 -1 -1
    1 5 15 2006 15 3 35 -1 -1
    1 5 15 2006 15 9 43 -1 -1
    1 5 15 2006 15 15 51 -1 -1
    1 5 15 2006 15 21 59 -1 -1
    1 5 15 2006 15 28 6 -1 -1
    1 5 15 2006 15 34 15 -1 -1
    1 5 15 2006 15 40 24 -1 -1
    1 5 15 2006 15 46 33 -1 -1
    1 5 15 2006 15 52 40 -1 -1
    1 5 15 2006 15 58 48 -1 -1
    1 5 15 2006 16 4 56 -1 -1
    1 5 15 2006 16 11 5 -1 -1
    1 5 15 2006 16 17 14 -1 -1
    1 5 15 2006 16 23 24 -1 -1
    1 5 15 2006 16 29 32 -1 -1
    1 5 15 2006 16 35 39 -1 -1
    1 5 15 2006 16 41 47 -1 -1
    1 5 15 2006 16 47 55 -1 -1
    1 5 15 2006 16 54 4 -1 -1
    1 5 15 2006 17 0 13 -1 -1
    1 5 15 2006 17 6 23 -1 -1
    1 5 15 2006 17 12 31 -1 -1
    1 5 15 2006 17 18 39 -1 -1
    1 5 15 2006 17 24 46 -1 -1
    1 5 15 2006 17 30 55 -1 -1
    1 5 15 2006 17 37 3 -1 -1
    1 5 15 2006 17 43 12 -1 -1
    1 5 15 2006 17 49 20 -1 -1
    1 5 15 2006 17 55 29 -1 -1
    1 5 15 2006 18 1 36 -1 -1
    1 5 15 2006 18 7 44 -1 -1
    1 5 15 2006 18 13 53 -1 -1
    1 5 15 2006 18 20 2 -1 -1
    1 5 15 2006 18 26 12 -1 -1
    1 5 15 2006 18 32 20 -1 -1
    1 5 15 2006 18 38 29 -1 -1
    1 5 15 2006 18 44 36 -1 -1
    1 5 15 2006 18 50 45 -1 -1
    1 5 15 2006 18 56 54 -1 -1
    1 5 15 2006 19 3 3 -1 -1
    1 5 15 2006 19 9 10 -1 -1
    1 5 15 2006 19 15 18 -1 -1
    1 5 15 2006 19 21 26 -1 -1
    1 5 15 2006 19 27 34 -1 -1
    1 5 15 2006 19 33 44 -1 -1
    1 5 15 2006 19 39 53 -1 -1
    1 5 15 2006 19 46 3 -1 -1
    1 5 15 2006 19 52 12 -1 -1
    1 5 15 2006 19 58 20 -1 -1
    1 5 15 2006 20 4 30 -1 -1
    1 5 15 2006 20 10 38 -1 -1
    1 5 15 2006 20 16 50 -1 -1
    1 5 15 2006 20 23 0 -1 -1
    1 5 15 2006 20 29 9 -1 -1
    1 5 15 2006 20 35 17 -1 -1
    1 5 15 2006 20 41 24 -1 -1
    1 5 15 2006 20 47 32 -1 -1
    1 5 15 2006 20 53 40 -1 -1
    1 5 15 2006 20 59 49 -1 -1
    1 5 15 2006 21 5 59 -1 -1
    1 5 15 2006 21 12 8 -1 -1
    1 5 15 2006 21 18 16 -1 -1
    1 5 15 2006 21 24 23 -1 -1
    1 5 15 2006 21 30 31 -1 -1
    1 5 15 2006 21 36 40 -1 -1
    1 5 15 2006 21 42 49 -1 -1
    1 5 15 2006 21 48 57 -1 -1
    1 5 15 2006 21 55 5 -1 -1
    1 5 15 2006 22 1 12 -1 -1
    1 5 15 2006 22 7 20 -1 -1
    1 5 15 2006 22 13 28 -1 -1
    1 5 15 2006 22 19 38 -1 -1
    1 5 15 2006 22 25 48 -1 -1

  • How can we read some bytes from every line of the file

    How can we read some bytes from the every line of the file moving on to the next line
    without using the read line

    Actualiy readLine() takes more execution time
    for reading a part of line if we can do so without
    readLine() we can save some time...Well, if you knew, beforehand, the length of each line, you could use RandomAccessFile and its seek method, but, since you don't, you would have to read the rest of the line character-by-character, checking to see if it is a newline, in order to place the "cursor" at the beginning of the next line in order to read the next few characters you want.
    So, as you can see, you will need to read the entire line anyway (and if you do it yourself you also have to do the checking yourself considering all three possible end-of-line sequences), so you just as well use readLine().
    Some people may suggest Scanner and it's nextLine() method, but that also needs to read the rest of line (as evidenced by the fact that it returns it), so that is no different than the readLine() (or read it yourself) solution.

  • I want to write a program to download file from particular location

    I want to write a program to download file from particular location to client side in jsp.
    Need guidance...

    Hi Hello333,
    You have to use a servlet :
    public class SomeServlet extends HttpServlet {
        public void doPost(HttpServletRequest req, HttpServletResponse resp) throws
                                   ServletException, IOException {
            ServletOutputStream out = resp.getOutputStream();
            resp.setContentType("application/pdf"); // here is an example for a PDF file
            resp.setContentLength(fileLength); // length of the file
            out.write(fileBinaries); // the binaries of the file
    }

  • Read data from a .csv located on another server

    Hi!:
    I've an application that currently reads some data from a .CSV file that I upload everyday using a file browser item plus a custom procedure to parse it. I was wondering if it'd be possible to automatically read the information from a remote file located in a web server. I've been looking for ways to do this, but couldn't find anything. Do you have any ideas?.
    thanks for your help!

    I'm pretty sure the answer is no, if it's not on the database server.
    However (this isn't my area of expertise really) if your server admins have the ability to somehow mount a network drive (or volume? sorry i don't know the terminology or details) to the database server and then, as far as the database server is concerned, the file looks/walks/talks as if it's local on the same box and then you can reference it via UTL_FILE, an external table, etc.

  • Inserting strings in a RandomAccessFile at a particular location

    I wrote a java program to read and display the contents of RAF. It is working. Actually,I need to read a file and search for a string in it and if the string equals certain value, then i need to insert a line in the file at that location.
    My problem is I am not able to insert any string in the RandomAccessFile(RAF) at a particular location, it always overwrites the already present string.
    I have a file called SOE_Arrays2.js which needs to be read and its content has to be modified. I am searching for a string like "os = [" in it and inserting another line like "["64w","64-bit Windows"]," at that location.
    the file looks like this:
    os1 = [
    ["win","Windows"],
    ["unx","UNIX"],
    ["mvs","MVS"]
    os2 = [
    ["alp","Alpha VMS"],
    ["lnx","Linux"]
    var letter = [
    ["new","New"],
    ["addon","Add-on"],
    ["lsf","LSF"],
    ["renew","Renewal"]
    The java program i wrote is here:
    import java.io.*;
    public class RAFtest
         public void writeTo()
              try
         String f = "C:\\webapps\\oncall\\soe\\SOE_Arrays2.js";
         File arrayfile = new File(f);
         RandomAccessFile raf = new RandomAccessFile(arrayfile, "rw");
         String s="",ss="";
         int i,j = 0,len;
         long fp;
    while((s = raf.readLine()) != null)
              //System.out.println(s);
              int ptr = 0;
              ptr = s.indexOf("os2 = [");
              if(ptr != -1)
                   System.out.println(s);
                   System.out.println("The OS array is here:");
                   ss = s;
                   raf.writeBytes("\r\t");
                   fp = raf.getFilePointer();
                   raf.seek(fp-4);
              raf.writeBytes("[\"64w\",\"64-bit Windows\"],\r");
                   break;
         raf.close();     
         catch(Exception e){e.printStackTrace(System.out);}      
         public static void main(String args[])
              RAFtest e = new RAFtest();
              e.writeTo();
    After executing the code SOE_Arrays2.js looks like this:
    os1 = [
    ["win","Windows"],
    ["unx","UNIX"],
    ["mvs","MVS"]
    os2 = [["64w","64-bit Windows"],
    lnx","Linux"]
    var letter = [
    ["new","New"],
    ["addon","Add-on"],
    ["lsf","LSF"],
    ["renew","Renewal"]
    you can see that RAF overwrites to the file at that particular location( after the line "os2 = [ ". What i need is to insert the text at a particular location, Is there a way to do this?
    I tried to insert carriage return, etc and move the file ptr back a little and write, whatever it is, RAF overwrites it, is there a way to insert instead of overwrite?
    Basically I want to get some string from the user from a web page and insert that string in my SOE_Arrays2.js file at a particular location depending on certain conditions.
    Is there another way of doing this instead of RAF?
    Please let me know how to do this.
    Thanks,
    Priyha.

    Hi DrClap,
    Thanks for the clarification. Everything works except the renameTo() . I am trying to rename the arrayfile2 to arrayfile1 , but the rename always return false. I am not sure why rename is not successful.
    I checked for the permissions of the file, full permission is there. I closed the files before renaming.
    Here's the code.
    import java.io.*;
    public class RAFtest
    public void writeTo()
    try
    String f1 = "C:\\JAVA\\SOE_Arrays2.js";
    String f2 = "C:\\JAVA\\SOE_Arrays3.js";
    File arrayfile1 = new File(f1);
    File arrayfile2 = new File(f2);
    RandomAccessFile raf1 = new RandomAccessFile(arrayfile1, "rw");
    RandomAccessFile raf2 = new RandomAccessFile(arrayfile2, "rw");
    long fp1=0,fp2=0; // file pointers
    String s="",ss="";
    int i,j = 0,len;
    boolean b= false;
    raf2.seek(0);
    while((s = raf1.readLine()) != null)
    int ptr = 0;
    raf2.writeBytes(s);
    ptr = s.indexOf("var OS9.1_sol = [");
         if(ptr != -1)
              System.out.println(s);
              System.out.println("The OS array is here:");
              ss = s;
              fp1 = raf1.getFilePointer();
              raf2.writeBytes("[\"64w\",\"64-bit Windows\"],");
              fp2 = raf2.getFilePointer();
              break;
    raf1.seek(fp1);
    while((s = raf1.readLine()) != null)
         raf2.writeBytes(s);               
    raf1.close();
    raf2.close();
    if(arrayfile2.exists()) System.out.println("file2 exists!");
    try{
    b = arrayfile2.renameTo(arrayfile1); //rename the file, why does it return false?
    }catch(SecurityException se){se.printStackTrace(System.out);}
    catch(NullPointerException ne){ne.printStackTrace(System.out);}
    System.out.println("b: "+b);
    catch(Exception e){e.printStackTrace(System.out);}
    public static void main(String args[])
    RAFtest e = new RAFtest();
    e.writeTo();
    here is the SOE_Arrays2.js
    var OS9.1 = [
    ["win","Windows"],
    ["unx","UNIX"],
    ["mvs","MVS"]
    var OS9.1_sol = [
    ["alp","Alpha VMS"],
    ["lnx","Linux"]
    var letter = [
    ["new","New"],
    ["addon","Add-on"],
    ["lsf","LSF"],
    ["renew","Renewal"]
    Please let me know whats wrong with the above code. I have no clue why renameTo returns false.
    Thanks,
    Priyha

Maybe you are looking for

  • Error on generating reports from forms -- 499 Oracle SSO

    hai friends.. while am tryng to generate a report from a form(without passing any parameters), am geting the following message: *499 Oracle SSO* Oracle SSO am posting my code used: PROCEDURE RUN_REP_RRO ( ip_report_name_incl_path VARCHAR2, ip_report_

  • Problems joining Wi-Fi networks that require viewing a redirect page in iOS 8.1.1? Check your "Auto-Login" setting.

    Are you having problems joining previously used Wi-Fi networks that require you to view a login or redirect page (say to accept Terms of Use) first?  The problem could be your Auto-Login Wi-Fi network setting. I found numerous cases where I could not

  • Pages not installed properly

    I am trying to dowload the application that i paid for and the apps page says unable to dowload and that it is an error. How can i finally download the app that i paid for?

  • Logic for data transfer

    Hello, I have a requirement, wherin there are 10 tables for which the data changed/inserted/deleted for any field needs to be transferred to third party. I have gone through the change pointer concept and found that SAP does not recommend this as thi

  • How to make export with sensitive user data encrypted?

    My organization need a backup dump of prod database sent to a customer, but want me to encrypt some user's password, and some data. Which expdp parameter can do that? Or any way I can do that ? Thanks in advance.