How to display random lines from txt file

Good morning (or evening all). I am creating an application and want to display random lines of a text file. I know how to create a text file using file connections, but how can I read the random lines of her?

OK I got it.

For beginners like me to have a problem in the future, I was not specify my path correctly. It is not enough to land your .txt in the /res folder and wait for the Simulator to load. You must load from SD card or device memory.

Use the method found here:

http://www.weask.us/entry/J2ME-BlackBerry-read-write-text-file

to use it's as simple as that

StringfName = "file:///SDCard/Blackberry/text.txt";

String printLine = readTextFile (fName);

label.setText (printLine);

Somewhere in your project directory create a directory called SDCard (I did in my res folder).

In the Simulator go to switch SD card, then load Select Directory and select the new directory of the SD card. This will create the structure of the SD card in the Simulator. Simply move your .txt in the SDCard/Blackberry directory and run your application.

Tags: BlackBerry Developers

Similar Questions

  • How to display an image from the file in the database

    I want to be able to display an image from the file that I have stored in a database. In the database, the image is store as a file with numbers. When I go to display only the sign of an image appears. I want to be able to display the image not the symbol for numbers of the image or file. I know I'm close I just can't understand what I'm messing, to get the image to display.

    Here is the code:

    <? PHP require Connections/Connections.php"?" >

    <? PHP

    session_start();

    {if (isset($_SESSION["fname"]))}

    }

    else {}

    Header('Location:NewRequest.php');

    }

    ? >

    <? PHP

    $User = $_SESSION ['Pnom"];

    $result = $con-> query ("SELECT ALL * from newrequest where Fname ="$User"" ");

    ? >

    <! doctype html >

    < html >

    < head >

    < link href = "CSS/Master.css" rel = "stylesheet" type = "text/css" / > "

    < link href = "CSS/Menu.css" rel = "stylesheet" type = "text/css" / > "

    < meta charset = 'utf-8 '.

    ReviewRequest < title > < / title >

    < / head >

    < body >

    < div class = "Container" >

    < div class = "Header" > < / div >

    < div class = "Menu" >

    < div id = 'Menu' >

    < nav >

    < ul class = "cssmenu" >

    < li > < a href = "Account.php" > account < /a > < /li > ""

    < li > < a href = "UpdateAccount.php" > update account < /a > < /li > ""

    < li > < a href = "NewRequest.php" > new request < /a > < /li > ""

    < li > < a href = "ReviewRequest.php" > Review Request < /a > < /li > ""

    < li > < a href = "LogOut.php" > sign out < /a > < /li > ""

    < /ul >

    < / nav >

    < / div >

    < / div >

    < div class = "LeftBody" > < / div >

    < div class = "RightBody" >

    < name of the form = "form1" method = "post" action = "" >

    < table border = "1" >

    < b >

    < td = '26' height > name < table >

    Location < td > < table >

    Description < td > < table >

    Image of < td > < table >

    < Td > status < table >

    < /tr >

    <? PHP while ($row = $result-> fetch_assoc()) {? >}

    < b >

    < class td = "GFied" > <? PHP echo $row ["Fname"];? > < table >

    < class td = "GFied" > <? PHP echo $row ['Location'];? > < table >

    < class td = "GFied" > <? PHP echo $row ['Description'];? > < table >

    < class td = "GFied" > < img src = "<?" PHP echo $row ["numero_imagenom_image"];? > "alt =" "> < table >"

    < class td = "GFied" > <? PHP echo $row ['Status'];? > < table >

    <? PHP}? >

    < /tr >

    < /table >

    < / make >

    < / div >

    < div class = "Footer" > < / div >

    < / div >

    < / body >

    < / html >

    This is what it looks like when it displays:

    Capture3.PNG

    How can I actually picture to display?

    emrenilo32520834 wrote:

    I added the .jpg but the image still does not display, the images are saved in a jpg file.

    If the images in the database to follow this format - 1234567.jpg, 9897654.jpg

    Then your original code must have worked:

    Are the images in their own folder, if so you need to add this folder for code name:

  • Remove # and clear the line from txt files

    Hello

    I have problem with my program.

    I need to remove the empy lines in my txt file.

    This is file look like:

    # Standard capacitance data file
    # Model capacity: parallel (K = 3.0)
    # Created by: ECT32v2 for Beta2.25 of Win32 (July 10, 2003 01:54:24)
    # Source: rec_flow_f45_v800_n2.bcp
    # Description: contents of the buffer to capture mode
    # Date: 12:04:43 GMT standard time, 29 March 04
    # Electrodes = 8, measures = 28
    # Data for plan 1

    # 1 frame (0 msec)
    0.006-0,001-0.004-0, 002 - 0.028-0.031-0,002
    -0.008-0, 005 - 0.007 - 0.024 0.005 0.004
    -0.014-0, 002 - 0.011-0.004 0.002
    -0.008 - 0.003 - 0.004 0.003
    -0.011 0.001 0.002
    0.005 0.004
    0,008

    # structure 2 (10 ms)
    -0.002 0, 005 - 0.008 0.006-0,002 0,023 0.011
    -0.008-0.004 - 0.004 - 0.003 0.010 0.001
    -0.007-0,001-0,012 0.007 0,008
    -0.015-0.004 0.002 0.001
    -0.007-0,002 0.001
    -0.002 0,008
    0.005

    I want to remove all empty lines, lines containing ' # '.

    I try as an attachment, but it does not work.

    How can I do this?

    Regads,
    Sorry for my English

    Ben Merci for example. Somehow, I missed the framework which enabled search expresion. Your example has sent me to the help files to understand. I have modified my first code for the show method, I hope I have the correct explanation. Not trying to do someones homework for them, but for those who need a quick start, maybe this will help someone else along the way.

  • How to transfer a picture from a file to display on a site like craigslist?

    How to transfer a picture from a file to display on a site like craigslist? Donald strickland

    http://www.craigslist.org/about/Help/FAQ

    Read the FAQ in the link above.

    Can I add an image to my ad?

    In some categories, you will be offered the option to add Images to your listing during the validation process.

    In addition, you can do this by using the HTML tag, but the image must already be on a website somewhere. There are many sites of free web hosting on the internet where you can upload your photo, just type "free hosting" in your search engine. Make sure that the site allows you to make a link to their site from another. If it's on a site, say on www.craigslist.org, in a directory named/on/teamPix, and named homer.gif, you had the code:

    It would look like the picture you see on the right. (The align and alt attributes are useful, but not necessary.)

    If you do this, you use HTML, so see the next question.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://www.ehow.com/video_4985809_add-image-ad-Craigslist.html

    Watch the video above.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://www.ehow.com/how_4667535_post-great-photos-Craigslist.html

    You want the secret to post pictures on craigslist? Well, the secret is www.photobucket.com (an online photo album)

    See you soon.

    Mick Murphy - Microsoft partner

  • How to generate random numbers from 1 to 5

    How to generate random numbers from 1 to 5

    -1110340081

    Thank you I ended up

  • How to install Windows 7 from this file img or md5?

    What should I do with the IMG file?

    I downloaded Windows 7 Professional 64 bit in an online store so I could move to 64-bit Windows Vista Home Premium (discount student/teacher). I clicked on the launch button installation. He said that he could not run the file img (en_windows_7_professional_win64_x15 - 79946.img). The only other file in the download folder (c:\temp\new) is as follows: X 15 - 79946.img.md5. How to install Windows 7 from this file img or md5?

    Thank you
    Jack

    Please see the following:

    http://social.answers.Microsoft.com/forums/en-us/w7install/thread/13450eb9-B158-4c95-be1e-a13fe03f0632 - how to make a ISO

    Upgrade paths:
    When important changes to your computer, for example an upgrade, it is always recommended that you back up your system before installing a new version of Windows. In your case, you can upgrade to Windows 7 depending on the edition and the architecture of Windows Vista, you have installed. If you are running a 32-bit version of Vista and upgrade to a 64-bit (Windows 7 edition) version, you'll have a pure make install, it is the opposite case.

    If you are using Windows Vista Home Basic or Premium consumer editions, you can only upgrade to Windows 7 Home Premium or Ultimate. In addition, you can make downgrades, which means, if you are running Windows Vista Ultimate Edition now, you cannot downgrade to Windows 7 Home Premium. You perform logical upgrades:

    Windows Vista Home Basic > Windows 7 Home Basic, Premium or Ultimate
    Windows Vista Edition Home Premium > Windows 7 Home Premium or Ultimate
    Windows Vista Business > Windows 7 Professional, enterprise or ultimate edition
    Windows Vista Business > Windows 7 Enterprise
    Windows Vista Ultimate > Windows 7 Ultimate.

    Andre Da Costa http://adacosta.spaces.live.com http://www.activewin.com

  • How about the text of the .txt file output?

    This is my code:

    #include "iostream.h".

    #include 'fstream.h.

    ofstream myfile;

    MyFile.Open ("C:\test.txt");

    MyFile < < 'text ';

    MyFile.Close ();

    But it occurs the error C1083: cannot open include file: 'iostream.h': no such file or directory.

    How about the text of the .txt file output?

    I would suggest that you do in the InDesign style to match...

    InterfacePtr stream (StreamUtil::CreateFileStreamWrite (...);

    if(Stream->GetStreamState() == kStreamStateGood) {}

    flow-> XferByte (buf, size);

    flow-> Flush();

    }

    flow-> Close();

    There are lazy as CreateFileStreamWriteLazy equivalent methods.

    Deferred methods will open the file in the application, but you will always get a valid pointer.

    See docs on its use.

  • Real-time display and receive data from txt files

    Hello

    I am creating a Flash component and I'm doing an editor for him.

    The component itself receives all its parameters to a .txt file.  The editor is a form of reading/record, that initially loads the settings in the form fields, then replace the .txt file when the user presses submit.  Then, you update the component on any Internet site, you have to see the changes.  I plan also to import the swf of the component in the editor.

    Here is the php code I found to help me will do:

    <? PHP
    Enter the data in the table of $_POST
    $title = $_POST ["title"];
    $comments = $_POST ['comment'];
    $image = $_POST ['image'];
    Make a chain in a Flash format
    $toSave = "title =". "." $title. "& comments = '. '. $comments. "& image =". " $image;
    Open a file in write mode
    $fp = fopen ("anastasio.txt", "w");
    If (fwrite ($fp, $toSave)) echo "write = Ok;
    else echo "write error";
    fclose ($FP);
    ? >

    If I have correctly configured as3 to send and receive on the fields of form a dozen as an experiment.

    What I want to do now is to do more in real time, so that the changes are reflected in the component that the user types parameters in, rather than submit them htting and then having to refresh the component swf to see the changes.

    What is a good way to go about this?

    Thanks for your help on this one.

    Shaun

    AS3 textfields have a change event that is sent when a textfield text changes.  You can use it to update your text file.  refresh a component in another swf file will require you to use the localconnection class to communicate between the two rulers.

  • Import data from txt file with the reading of the names of columns

    Hello

    After changing the export of my simulation program, I can't use the postet heresolution, that works well. (I mark the message as hailed this is why I run a post only)

    Can anybode if you please tell me how to fan the code to import the new txt file type. The names of the columns here are FOA online first columns, like this (with ignoring the first lines).

    Hello Gabriel

    You can use the use wizard (Navigator > file > use wizard) to define a new filter to import file for your data. It will take only a minute.

    Please find the uri of the file that I create for you. Copy the attached file in your disk, unzip it and double-click the file uri.

    Then you can open your file by using 'open with '.

    Hope this helps

  • How to load a text from a file of editbox?

    Hello

    I use a tiara script to load data and a report... For this I load the data and the report apeare, with a dialog (ProtocolDlg2) were I can chose to change variables to report or print the report.

    My question is how can I load into the editing area of the DialogBox (ProtocolDlg2), the variables (in my script there is the Datasetcomments from 1 to 11).

    I want to when I opened the dialog box - ProtocolDlg2, all the data in the report (TO; DVM; The sample number; ....) will apear in the editboxes and to have the opportunity to change and then print the report again, and close the application.

    The datasetcomments are from a txt file. This application is part of a VBA application.

    You have my script and my attached file. SOUTH

    Thank you for your time.

    Hi again,

    If this is not possible with the edit box (I have try with a table too, but without success), please tell another way I can load the report and change the data in the report, so I can print after that.

    Thank you once again.

  • How to write output to a txt file query results

    have a sub query resulting in some records I want to write in a txt file

    Select employee a.empcode a, b the address where a.empcode! = b.emp.code

    You can use UTL_FILE to do so, either specifically for your query or more generically as below:

    As user sys:

    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    /
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /
    

    As myuser:

    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      --
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    

    This allows the header line and the data to write into files separate if necessary.

    for example

    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    
    PL/SQL procedure successfully completed.
    

    Output.txt file contains:

    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    

    The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

    Adapt to the exit of styles and different types of data are needed.

  • Remove the string from txt file

    I have a .txt file (see table) I use the spreadsheet for the array function to retrieve the data I need. I am trying to extract over time of Inspection and the number doubles alongside that separately, but I have a problem with the delimiter. The .txt file will still not of this size, but the 1st and the last line will be the same


  • Import data from txt file and name the channels

    Hello

    I want to import data from a file txt (see attachment). Well well, no proplem, but I want to also read the information on the channel names and units and rename the imported channels. Is it possible to do? It is also important that the number of channels may vary.

    Can someone give me some examples of code?

    Thank you very much

    Gabriel

    Hello Andreas,

    Thanks for your work. I'll adjust the code.

    Gabriel

  • How to display e-mails from multiple accounts in windows mail?

    I created a second e-mail account in windows mail (WLM, NOT) but I can't figure out how to display messages sent to this account.  I asked my sister to send a test message to this special address and when I hit send/receive I don't receive it.

    Hi Jason,

    Please ensure that you have followed all the steps listed in this thread for your second e-mail account. It seems that the messages do not come through your Inbox, which leads me to believe one or more of the following are has been forgotten. http://Windows.Microsoft.com/en-us/Windows-Vista/Windows-mail-setting-up-an-account-from-start-to-finish

    I hope this helps and please post back with the results.

  • How to remove common locations from the file tab in the file Explorer?

    When I open file Explorer and tap the file it displays a list of frequent places invading my privacy

    When I open file Explorer and tap the file it displays a list of frequent places invading my privacy

    Hello

    I don't know what you mean by "invading my privacy?

    Frequent sites display only the folders and files that you opened in the file Explorer. Each user account displays only frequent places for this specific account. No other account can see the frequent locations for your user account.

    The frequent places are associated with the taskbar Jump Lists for applications that are pinned to the taskbar.

    You can right-click on the taskbar and select Properties.

    Select the tab lists Jump and remove the check from the 2 options you see here.

    This will disable the list of common places in the file Explorer and lists of shortcuts on the taskbar.

    Concerning

Maybe you are looking for

  • get messages saying that I have a trojan virus

    I get a message that safari has detected a trojan virus.  e.tre456_worm_osx Safari passes to mackeeper adds constantly asking me to download the application and run it etc etc. What is a valid warning or a scam... If scam how to stop system of consta

  • My iMac can boot from an external drive?

    Hello I have an iMac 21.5 "Mid 2010 which starts to show its age with slowness. However, I plan to upgrade the Basic 4 GB of Ram either 8 GB or 16 GB of Ram, depending on price... and my main question.  I know that the Mac came initially with a 500 G

  • Impossible to restart the iphone 6 after the white screen

    Screen went blank (White) disabled through holding "home" button and the Start button / stop together, phone expected to restart, but it didn't. attached to load but once again nothing... any ideas would be greatly received.

  • DJ3070 B611a: print and scan the doctor

    my printer HP DJ3070 B611a just stopped to connect to my network home. Windows Help (7/64) has not solved, so excited printing HP and doctor Scan. Upgrade of downloaded software, which gave (after download, install, a lot of time) gave an installatio

  • Color Laser Jet MFP M177fw Pro: Printer is not recognized by the devices.

    When connected to a computer via the usb - B to usb at the back of the device connection, computers do not get a signal telling them that they are connected to anything. The computer windows 7 behaves as there is nothing plugged and a Mac running 10.