Input reader

i am new to java so "forgive" my level of understanding. i need help in writing a program to read a sudoku puzzle from a file.the file should contain 9 lines of text, each line being nine characters long. the digits 1 to 9 will be in their correct positions and unknown positions/cells will be represented by the digit 0. once loaded the program should display the grid followed by a blank line.
I would greatly appreciate a prompt response as i nedd asap.
thx

You'll want to create your data file in notepad (not microsoft word) and save it as something like sudokupuzzle.dat. Or so I assume. I will also assume you're familiar with gathering lines from the user, it's very similar.
BufferedReader fin = new BufferedReader(new FileReader("sudokupuzzle.dat"));Inside the public class you'll need to use
public static void main(String args[]) throws IOExceptionThat BufferedReader bit will go after the public whatnot inside the curly braces.
Then to access it, you'll use a String variable (all data comes in as a String) and do something like:
input = (fin.readLine());When you do an fin.readLine() Java then goes to the next line it wants to get information from the .dat file, so the next fin.readLine() will grab the 2nd line. Be sure to remember that if you reuse the same variable, you'll lose the old variables, which is realtively obvious just making sure.

Similar Messages

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

  • Sound Input Read VI hangs

    I'm using the SI Read VI to sample from the Soundblaster card in my Dell PC. I've configured the device for 16-bit mono input, sample rate 44.1 kHz, and the buffer size is 1024 samples. The SI Read VI is in a Timed Loop whose period I've set to 23 ms (1024 / 44.1kHz). Following each acquisition, I do some filtering, frequency analysis, and plotting inside the loop.
    The acquisition works well for the first 10 minutes or so that it is running. But sometime after about 10 or 15 minutes, the VI hangs. I've traced the hang back to the SI Read VI, but have not yet figured out how to avoid the hang or recover from it (I have to abort and restart the program).
    Has anyone had similar problems with the SI Read VI? Could there be a problem with the DLL that the SI Read VI calls? Are there any upgrades or fixes for this? Can someone suggest a way to recover from the hang?
    Thanks for any help,
    Mark

    This message is a reply to "Sound Input Read VI hangs" (National Instrument) NI Discussion Forums posting found at: http://forums.ni.com/ni/board/message?board.id=170&message.id=137258 and http://forums.ni.com/ni/board/message?board.id=170&message.id=110656&requireLogin=False
    Hi everybody,
    From the large count of how many of you guys read the above thread of messages, including myself, and who are dealing with the same problem of SI Read VI hanging found National Instrument (NI) LabVIEW (LV), I decided to share my (not so perfect) solution with you guys to save you time and frustration. Here is the story of 3 days (18 hrs/day) of my life, fighting a bug in SI Read VI (SI: Sound Input) (I am currently using LabVIEW Pro v 7.1.1):
    For the reason that "A Message cannot exceed 10,000 characters" on this Forum I included my message in the attached Word doc. Hopefully, there is no such limitation on uploaded files!
    Samir Berjawi
    Research Assistant and Lab Instructor
    American University of Beirut
    [email protected]
    [email protected]
    Attachments:
    LabVIEW SI Read freezes - Report.doc ‏39 KB
    Sound Acquisition Test.zip ‏995 KB

  • How to best format input read from a file to a string

    I am trying to set up a class to convert input read from an xml-file to a java-string, which I can pass on to a web service.
    My attempt is probably not the smartest, but what I did was to set up a for-loop, which iterates through each line in the xml, appending "\n" to the end of each line, before storing them in a variable, which is loaded into an arraylist. When there are no more lines to read in the xml-file, the for-loop should terminate and the contents of the ArrayList should be written to a string, which is then returned.
    Below is my attempt to implement this - thanks in advance!
    import java.io.*;
    import java.util.*;
    public class RequestBuilder {
         private String _filename, output;
         //Constructor method
         RequestBuilder(String filename){
              String line;
              _filename = filename;
              //Sets up a array to store each line of XML read from a file
              ArrayList<String> lineList;
         lineList = new ArrayList<String>();
              try {
                   //Sets up a filereader and a buffer
                   FileReader fr = new FileReader(_filename);
                   BufferedReader br = new BufferedReader(fr);
                   //Iterates through each element of the arraylist until empty
                   for (String o : lineList){
                   //Stores a single linein a variable and appends a line-break
                   line = br.readLine() + "\n";
                   //Addseach line to the arraylist
                   lineList.add(line);
                   //Closes the filereader
                   fr.close();
                   //Writes the arraylist to a string
                   output = lineList.toString();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public String getRequest(){
              return output;
    }

    799992 wrote:
    Well, the reason for doing an ArrayList was that I had to process each line with line breaks and escape characters, but I know realize that I can do the same thing by summing the lines for each iteration directly intro a string like below - it works :-)
    Apparently the filereader takes care of double-quotes as I don't see any difference in the output when I disable the logic I made, which substitutes " with \", can anyone confirm this?
    The code I ended up using:
         //Sets up a filereader and a buffer
                   FileReader fr = new FileReader(_filename);
                   BufferedReader br = new BufferedReader(fr); 
                   //initializes the output variable with the first line from the file
                   output = br.readLine() + "\n";
                   while (br.ready() == true) {
                        //reads each line, saves it in a variable and appends line breaks
                        line = br.readLine() + "\n";
                        //Replaces adds escape character to any double-quotes (apparently not neccessary?)
                        tmpLine = line.replaceAll("\"", "\\\"");
                        line = tmpLine;
                        //sums each line in the current string
                        output = output + line;
    As EJP said you can directly write to the webservice. If you want to check for yourself what the result looks like just read the file without adding anything.
    public String readFile(){
         String xmlString = "";
              try{
                   String line = null;
                   xmlFile = new File(//file);
                   reader = new BufferedReader(new FileReader(xmlFile));
                        while((line = reader.readLine()) != null){
                             xmlString += line;
              catch(FileNotFoundException e){
                        e.printStackTrace();
              catch(IOException e){
                        e.printStackTrace();
         return xmlString.replaceAll("\\s+"," ").trim();//remove spaces
    }

  • Wrong sampling rate from Sound Input Read VI on Dell Latitude E6510

    Hi,
    When I
    receive data from the sound card with the Sound Input Read VI, the actual
    sampling rate is not equal to the sampling rate set in the Sound Input
    Configure VI. I estimate the sampling ratio by dividing the number of samples received
    by the difference between the first and the last t0 from Sound Input Read. For
    example, if the sampling rate is set to 7000 S/s, the actual sampling rate is
    around 6900 S/s. If the sampling rate is set to 7050 S/s, the actual sampling
    rate is around 7200.
    This problem appears when the
    code is run on my Dell Latitude E6510 machine. When I run the
    same code on my Lenovo ThinkPad, the sampling rate is correct.
    The Labview application I
    am developing is to be used to acquire data synchronously from several sources,
    including the sound card input. It is therefore important that the sampling rate
    is correct.
    If anybody has any idea
    about what may cause this problem, and a way to fix it, I would be grateful.
    Ole

    It has been a trend the last years that sound card only support some sampling rates, not a range. You should refer to your sound card manual for this kind of information.  You should also be aware of that the NI sound interface is junk, and they do care about it either. Use the WaveIO interface instead See the link. But I am quite sure your problem is related to the sound card hardware not some NI driver issue
    http://www.zeitnitz.de/Christian/waveio
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • Time mismatch with Sound Input Read VI

    Hi Folk,
    I am acquiring the signal of the PC
    sound card with the "Sound Input Read VI" and I have
    noticed that between subsequent waveform data packets there are time
    mismatch, both overlap and gap.
    To point out the observed behavior, I
    have posted a modified example, the "Continuous Sound Input.vi". In the example, I have computed the
    time difference between the t0 of the actual waveform packet and t0
    expected on the basis of the previous waveform packet.
    Consistently, in the indicator "Time
    series" (Waveform Charts), each time there is a time overlap or
    gap the Charts resets it self or presents a gap.
    By reading 1 second of data the time
    mismatch is about 0.015625 or 0.03125 sec. (both positive and
    negative).
    The repetition frequency of the time
    mismatch decreases as the acquisition sample rate increases.
    The amount of the time mismatch seems
    to be sample rate invariant.
    Do you have any idea from where this
    problem is coming out and how to solve it?
    Thanks for your help,
    Asper
    Attachments:
    Time mismatch with Sound Input Read VI.png ‏51 KB

    Pre made Labview functions are not some holly grails that is newer to be touched and modified. In fact many included functions in Labview has what I will name as "high flimflam factor" That will say a lot of functions you do not really need. Express VIs are grim examples of this.
    Anyway I have made some modifications and removed some babyfat in the sound input VI. Take a look at it. The top level VI is the "time fixed sound.vi" It could be that you will get an error because Labview will not find a DLL. If a DLL is reported missing you will find it in C:\Program files\National Instruments\LabVIEW 2010\resource\lvsound2.dll
    Remember to save the modified VIs in a separate folder, and not in the vi.lib folder at all. Be careful so you do not overwrite any Labview function
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    Sound Input Read (DBL)_time_fixed.vi ‏30 KB
    time fixed sound.vi ‏19 KB

  • Smart Camera Input reads low

      I have a 1722 Smart Camera.  I can't get the inputs to read a "high" value.  Other than this, my application works well.
      I'm using the NI cable and screw-terminal block.  If I jumper any of input 0 or 1 (pin 2 or 8) to +24V (pin5), still the inputs always read low, so I can never get past the step that waits for a "high" input before proceeding.  I used the data monitor as well while applying the voltages, but they always read "0".
      Note: the outputs also don't work; they always are at 24V even when set low (they have pullups to +24).
      The LEDs though work fine when I turn them on and off.
      What am I missing conceptually to have inputs read?
    Solved!
    Go to Solution.

    1)  Yes, it's the NI Vision I/O Terminal Block.  The power supply is a high quality 24V, 5A MeanWell regulated supply going into the terminal block.
    2)  The system itself works well (inspections are passed/failed correctly), so I don't think it's the power supply connection.  However, the power supply is connected to the +24V and ground terminals on the block (pin 5 and 15, I believe from memory)
    3)  I tried reading a few different ways.  (a) the Test Panel, which comes up when I double click the I/O logic block in Vision Builder AI (2011). I both shows the state, and also can chart the real-time values in a plot if the values are double-clicked.  (b) the VBAI application itself, where an exit condition from the very first state is waiting for a pin to go high.  This state never leaves, unless I set the exit condition to Low (which is what the system always reads).  I connect the two isolated input pins 0 and 1 (terminal 8 and 11 on the screw terminal block, again from memory) to +24V (terminal 5), so both inputs should be able to read High.
    4) The LED indicators cycle through their startup sequence, then the Power is lit as it should, and the status LED is on as well.  The Fail and Pass LEDs work as they should, as mentioned (they were programmed to show a pass/fail condition, and then reset at the start of the next inspection loop).
      The outputs also don't seem to work despite pullups to +24.  They always seem to be low even when commanded high. I think, though, that at one point they might have briefly worked, so I suspect I'm doing something fundamentally wrong...

  • Inputs read from daq are overwritten

    Hey there
    I have a Daq input reading into a spreadsheet file
    The daq tells me that one is supposed to have a while loop around it, and I can't get it to run without one, so okay
    But my main problem is that this means that it overwrites my written file each time the while loop repeats
    It also asks me to choose the file to write in multiple times
    How would I go about fixing this?
    Thank you
    Solved!
    Go to Solution.

    Yes you can convert numeric to string, check the attached VI. I would recommend you to go through basic LabVIEW materials and also play with NI example which comes with LabVIEW. Remember do not use the attached example along with data acquisition, always use seperate loops.
    The best solution is the one you find it by yourself
    Attachments:
    Write2File.vi ‏19 KB

  • Sound input read multiple soundcards

    Heey everybody,
    I have a problem. I want to read two different signals at the same time from 2 different soundcards. 1 internal soundcard from my laptop, and 1 usb soundcard. 
    So i used the Acquire Sound VI.
    Reading both signals at the same time is not a problem until i set the measuring time to about more that 30 seconds. It gets a buffer overflow.
    So i tried to do the following:
    I first made this with 1 signal first, and it worked perfectly, every second it got updated.
    But, when i added the second signal it only wanted to read the first second of the first signal and then it got stuck, and i had to stop the software by closing it. And then killing labview with the taskmanagement thingey from windows.
    Anyone have any idea what the problem is?
    Greetings,
    Jory 
    Solved!
    Go to Solution.

    Ok, never mind, i've solved it. I made the buffers larger (at the sound input configure block) and now it works like a charm

  • Sound Input Read Spectrum Analyzer

    I am working on a project with Arduino to do a spectrum analyzer. The LVIFA part of it is working fine.
    The part that I am struggling with is the audio input.
    I am using the Sound Input Pallet.
    My troubles are two-fold.
    1. A single read takes quite some time and I need to have a pretty quick response. I decreased the samples per read and came up with problem #2.
    2. I can get one read out of the Sound Read In and then the VI locks up. I have my timeout set to 1 Sec and it never times out. I have to restart LabVIEW.
    While it would be nice to have this VI working, I'm not even sure that I am using the correct tool. If I am going to be running an audio spectrum analyzer display off of the data input, I need to response to be within a few mS (ie. <200) so that it looks visually correct.
    If this library will not achieve this, then I need to look into a different tool.

    Hi,
    I have a similar project, actually I am using a Audio frequency range as input to the Arduino and do an FFT to receive the spectrum out of it.
    See the YOUTUBE video I did and the code in *.jpg. I took actually the Continous Input example and modified it.
    Hope that helps.
    Keep me posted, since we might work on a same project.
    http://youtu.be/aqzyofQHXDM
    Y3G
    Attachments:
    Uno Blockpanel.JPG ‏104 KB
    Uno FRONTpanel.JPG ‏99 KB

  • Input Read Possible?

    How is this method of BufferedReader used
    public int read(char[] cbuf, int off, int len)...
    to read from an input stream when you
    don't know how many bytes you will be
    receiving.
    Is it possible?

    Read until getting -1
    BufferedReader br;
    // br = ...
    char[] buf = new char[1024];
    int count;
    String s;
    String allTogether = "";
    while ((count = br.read(buf, 0, 1024)) != -1) {
       s = new String(buf, 0, 1024);
       allTogether += s;
    // use allTogetherOr use a StringBuffer "allTogether" and his append method (it's faster).

  • PLEASE can a AE from NI take a look at my problem. Sound input read behave in strange manner then the buffer size is larger than 2X number of samples to read.

    On my computer I have discovered some strange behavior then reading data from the sound card. Then the buffer size is 2x samples to read everything is as expected. But since I read the sound card 10 times pr second I feel a .2 second buffer is to small. I am using XP, and XP is not a RTOS so with a buffer set to 0.2 seconds I may lose data. Therefore I set the buffer size (number samples/ch on Sound Input Configure.vi) to be in range of 2 seconds. The result then is that then reading from Sound input.vi, a reading often take more than 0.1 second. On my computer it is often 500mSec. Then the next 5 read follows with almost zero interval. I do not loose data. But on my front panel the graphs looks like an very early silent movie. This error was introduced in Labview 8.x. To be honest I think the labview 7.x sound system was much better in many ways.
    But before I point any finger NI. Other people has to verify the behavior I experience. I have made an example showing this error. It is a modified version  of the "Continuous Sound Input.vi" example. Then the "buffer in seconds" control is set to 0.2 every thing works OK. Changer this to a larger number will produce the mentioned above hiccup. The larger number in this control the larger hiccup. Is it any way to fix this? My solution up to now has to use a free 3. part software(http://www.zeitnitz.de/Christian/index.php?sel=wav​eio) But I guess it soon will be outdated. It may not work with newer windows versions.
    Any help at all will be appreciated 
    And yes I have the most updated version fo DirectX. Also I se this in Labview 2009 which I have trail version of. The VI I have made is in 8.6
    Message Edited by Coq Rouge on 09-07-2009 10:54 AM
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    Continuous Sound Input with timing.vi ‏23 KB

    macaba wrote:
    If you take a moving average of the 0.2s buffer vs. 3s buffer at an update rate of 10, then they are the same (just under 100ms), so the average refresh rate is the same. I agree that is odd behaviour that the time between sound reads go to zero quite a lot then take a long time once in a while (presumably to fill the buffer
    I guess it goes to zero because it is reading data from the buffer it do not has to wait for data from the sound card. The mysterious thing is the periodic delay. You are also correct then saying that average timing is correct. And in my application I have no data loss.
    If you search for sound in this forum you will find out that many people has reported trouble with the sound system.
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • My voltage input reading are floating around and cant seem to get an accurate reading of any kind. What is causing this?

    Im trying to input a DC voltate on channel 1. So i hook up +5 to the channel 1 analog input, and hook up ground to the AIGND. When i measure it in continous time, i get a reading of -1.3 V, when i move the cable connecting the NI board and the DAQ, the voltage jumps around. I even tried connecting AIGND straight to channel 1 analog input, and read a voltage of 2.3, but its not stable, it jumps around a lot. What is this problem. please help

    This is going to depend on how you have your DAQ board configured. In differential mode, the positive input is channel 0, but the negative input is channel 8 (for 8 differential/16 single ended MIO boards. Channel 32 is - on 32 differential/64 single ended MIO boards). (Similarly, chan 1 (+) and chan 9 (-) are the next channels, etc).
    For single ended mode, chan 0 is the +, and AIGND is the -.
    I suspect you have your board in differential mode, and your - is not connected to the correct pin; therefore, your voltage is floating.
    Mark

  • G5 sound input reads drums but no sound coming out

    i'm not sure what the deal is, the input is reading my drums fine but i hear no sound not through headphones or surround sound or computers speakers. All my sound works for anyhting else. please help me

    My present computer has no sound input capabilities but there may be a setting in sound control panels or whatever software you are using for selecting sound output, including passthrough. There's also a midi application in your applications that controls sound features.

  • How to have Sound Input Read VI read .wav in sections

    Hi,
    I'm trying to read audio data from my laptop's soundcard, and it's really slowing down my VI's processing power. I read on the NI website to read the .wav file in sections instead of as a whole, but I have no idea how to do that. Any suggestions? My VI is attached.
    Thanks!
    Attachments:
    signalgen.vi ‏56 KB

    You have set the sample rate for the sound card to 100000 samples pr second. That is a sample rate your sound card will not be able to handle. Hence a error will occur. And you will not get any data from the sound card. Some sound cards may support samplerates in 1 Hz step but most sound cards do only support some rates. The latter is most typical. All sound cards do support 44100 Hz sample rates but typical sample rates are 44100,22050,11025, and 8000. Some sound card do also support higher sample rates than 44100. Refer to your sound card documentation for this. Your way of using the Daq card by reading 1 sample on each iteration, using software timing is also a Daq NO-NO. Read data in chunks and do not do to many updates pr second, and always use HW timing. If you need the waveform to appear "live", or "real-time" 10 updates pr second is more than enough.  
    I have included a sample vi. I suggest that you use that as your workhorse from this point. At least if you want more help from me
    Tip Labview is shiped with many very useful examples. Then you are stuck. Go to toolbar->help->fFind examples. As one example the Daq setup is from the "Cont Acq&Chart Samples-Int Clk.vi" vi example
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    workhorse.vi ‏37 KB

Maybe you are looking for

  • Automatic Filing With Rules - Long

    This is a long post, sorry, but I think the details might be worthwhile for someone who might be like me and wants to automate their mail processing as much as possible. I do have a question below about how I might better configure some rules, and ab

  • Need General Information about VDS

    Hi, In our evaluation for different VDS, I require the following information. 1.Can we use hyphens in schema names? 2.Is it possible to map the VDS to any arbitrary position in the LDAP tree? 3.Will the VDS reflect the updates done by an LDAP client

  • Displaying XML content in the browser without creating the XML file

    Hi, In my web application, i am getting the data from the database and generating an XML file based on that. This file is created, read and its content is displayed in the browser when the user clicks a specific link on the jsp. As per the new requir

  • E Mail Forms and Spam Bots

    I have created a form and using a PHP script to forward the form results to an e mail account. How protected is this from harvesting the e mail address by spam bots? If this is not the best way to go, any suggestions on a better method. I'm familiar

  • Different time constraint for  0081-military service infotype and subty

    Hello I need as follows: To enable entry for each desired valid Subty. To enable ONLY ONE entry for each Subty. Time constraint T is not allowed for 0081 so I used Time constraint Z and I'm trying to maintain T591A. But I don't find the expected entr