Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

File open read to StringBuilder close Java example


BufferedReader , FileReader, StringBuilder , readLine, close Java example

Android example

String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
	int c; String sText = "";
	while((c=fis.read())!=-1)
	{

		sText += (char)c; // convert int to char
	 }
	fis.close();						



Java example

try {
	    BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
	    StringBuilder strBuilder = new StringBuilder();
	    String str;
	    while ((str = in.readLine()) != null) {
	       strBuilder.append(str);
	    }
	    in.close();
	} catch (IOException e) {
		e.toString();
	}


397LW NO topic_id



Další témata ....(Topics)


68

Write new file or append text Java Android example | write-file-java-android-example


BufferedWriter, FileWriter, write, close MODE_APPEND Java and Android example

Write to file Android example

try {
		String MYFILE = "my_file";
		String strText = "My text";

                // MODE_APPEND, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE
		// create new file or rewrite existing
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_PRIVATE);
                // append to file
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_APPEND);

		fos.write(strText.getBytes());
		fos.close();					
	} catch (IOException e) {
		e.toString();
    }	




Write to file Java example

try {
// new file    
BufferedWriter out = new BufferedWriter(
    		new FileWriter("outfilename"));
    // append text 
   BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true));
    out.write("some text");
    out.close();
 } catch (IOException e) {
   e.toString();
}			
240

AdMob in Android 4 version | admob-in-android-4-version


AdMob in Android emulator not visible?
You have to using some from this libraries:
GoogleAdMobAdsSdk-4.3.1.jar
GoogleAdMobAdsSdk-6.0.1.jar
GoogleAdMobAdsSdk-6.2.1.jar

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
    package="cz.okhelp.admob"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="13"
        android:targetSdkVersion="16"/>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
   

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
       <meta-data 
        android:value="a14d932xxxxxxxx" 
        android:name="ADMOB_PUBLISHER_ID" />
        <activity android:name=".AdmobActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

<activity android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
</manifest>


onCreate in your Activity.java

		@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     			AdViw adView = new AdView(this, AdSize.BANNER, "a14d932xxxxxxxxx");//MY_AD_UNIT_ID
    			LinearLayout layout = (LinearLayout)findViewById(R.id.idReklamaLayout);
				// Add the adView to it
    			layout.addView(adView);
				// Initiate a generic request to load it with an ad
				AdRequest adRequest = new AdRequest();
    			//adRequest.setTesting(true);
    			adRequest.setGender(AdRequest.Gender.MALE);
    			adView.loadAd(adRequest);
    }



main.xml (res/layout)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/idReklamaLayout"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="3" />

</LinearLayout>
80

List LinkedList add sort find Item in Java example | list-linkedlist-add-sort-find-item-in-java-example


List LinkedList Collections add sort find search Item, get searched item to string in Java example.

MainClass.java

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   
                   List<String> arrayList = new LinkedList<String>();
                  
                   for(String s: arrayOfString)
		     arrayList.add(s);

		    Collections.sort(arrayList);
		    // foreach
		    for (String str: arrayList)
		      System.out.println(str);
		    
		    Object objMin = Collections.min(arrayList);
		    System.out.println("Min is: " + objMin);
		    
		    Object objMax = Collections.max(arrayList);
		    System.out.println("Max is: " + objMax);
		    
		    int index = Collections.binarySearch(arrayList, "people");
		    System.out.println("Index of people is: " + index);
		    // print word on index 5
		    System.out.println("Index 5 is: " + arrayList.get(5));
                    String sItem = arrayList.get(5); // get item from index 5 to string
		    
		  }
}
/*
End
Hello
bye-bye
hello
nothing
people
world!
Min is: End
Max is: world!
Index of people is: 5
Index 5 is: people
*/
93

Android Emulator PC keyboard shortcuts | android-emulator-pc-keyboard-shortcuts


Basic shortcuts for Android Emulator.
























Emulated Device Key Keyboard Key
Home HOME
Menu (left softkey) F2 or Page-up button
Star (right softkey) Shift-F2 or Page Down
Back ESC
Call/dial button F3
Hangup/end call button F4
Search F5
Power button F7
Audio volume up button KEYPAD_PLUS, Ctrl-5
Audio volume down button KEYPAD_MINUS, Ctrl-F6
Camera button Ctrl-KEYPAD_5, Ctrl-F3
Switch to previous layout orientation (for example, portrait, landscape) KEYPAD_7, Ctrl-F11
Switch to next layout orientation (for example, portrait, landscape) KEYPAD_9, Ctrl-F12
Toggle cell networking on/off F8
Toggle code profiling F9 (only with -trace startup option)
Toggle fullscreen mode Alt-Enter
Toggle trackball mode F6
Enter trackball mode temporarily (while key is pressed) Delete
DPad left/up/right/down KEYPAD_4/8/6/2
DPad center click KEYPAD_5
Onion alpha increase/decrease KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)


More about Android Emulator
333

Android studio list of useful shortcuts or like Eclipse | android-studio-list-of-useful-shortcuts


File -> Settings -> Keymap you can do select Eclipse keymap from drop down menu

Ctrl+Shift+A (Help | Find Action on the main menu) and start typing the name of the action. Choose the desired action from the suggestion list.

Ctrl+Click (on Windows) or Cmd+Click (on MacOS) a tab in the editor to navigate to any part of the file path. Select the necessary element in the drop-down, and the corresponding file path opens in an external browser (e.g., in the Explorer, if your OS is Windows).

 

Find - Rename


Ctrl+F find

Refactor | Rename: Shift+F6  ( +F6)

Find and replace: CTRL + R

Go to variable declaration: CTRL + B

Ctrl+Shift+I (View | Quick Definition)

Ctrl+Alt+F7  (Edit | Find | Show Usages in the main menu)

Ctrl+Shift+F find in project

Ctrl+Shift+F7 (Edit | Find | Highlight Usages in File) to quickly highlight usages of some variable in the current file.
Use F3 and Shift+F3 keys to navigate through highlighted usages.
Press Escape to remove highlighting.

Ctrl+W (extend selection) in the editor selects the word at the caret and then selects expanding areas of the source code. For example, it may select a method name, then the expression that calls this method, then the whole statement, then the containing block, etc. You can also select the word at the caret and the expanding areas of the source code by double-clicking the target areas in the editor.

To search through the classes, files, tool windows, actions, settings, and symbols of your project by double pressing the Shift key

Ctrl+P (View | Parameter Info) e.g. localURL = new URL(localUrlString); select localUrlString and press Ctrl + P

Show html documentation tooltips:  CTRL + Q

 

Edit


Comment uncomment single line: CTRL + /

Comment uncomment selected text: CTRL + SHIFT + /

Code completion (Ctrl+Space)

Alt key and mouse pointer dragging for column selection

If nothing is selected in the editor, and you press Ctrl+C, then the whole line at caret is copied to the clipboard.

Ctrl + Delete  delete word from caret to end.

Ctrl + Backspace delete word from caret to start.

Duplicate line: CTRL + D

To compare two directories,or  jar files, select one or both of them in the Project view and press Ctrl+D.

Editor Delete Line: CTRL + Y

Move line UP, DOWN. Select a code fragment and press Ctrl+Shift+Up or Ctrl+Shift+Down.

To open any class or file in the editor at the desired line, press Ctrl+Shift+N (Navigate | File), start typing the name, and choose the one from the suggestion list. Then type the colon (:) and a line number

Ctrl+Shift+Enter to complete a current statement such as if, do-while, try-catch, return (or a method call)

Alt+Enter to invoke a quick fix or intention action, press the right arrow key to reveal the list of additional options.

To quickly review your recent changes to the project: Alt+Shift+C

Code Completion, you can accept the currently highlighted selection in the popup list with the period character (.), comma (,), semicolon (;), space and other characters.

Quickly move between methods in the editor:  Alt+Up and Alt+Down

Ctrl+Shift+J shortcut joins two lines into one and removes unnecessary space to match your code style

Ctrl+Shift+V to choose and insert recent clipboard contents into the text

Inheritance hierarchy for a selected class: Ctrl+H

Right-clicking on a breakpoint marker  you can quickly enable/disable the breakpoint or adjust its properties.

Evaluate the value of any expression while debugging the program, select its text in the editor (you may press a Ctrl+W a few times to efficiently perform this operation) and press Alt+F8.

Quickly evaluate the value of any expression while debugging the program, hold Alt and click this expression to see its value and calculate it, call a method, etc.

You can use the Extract Variable refactoring even on incomplete statements. Just select the necessary block in the editor and press Ctrl+Alt+V.

To open any particular method or field in editor: Ctrl+Alt+Shift+N

Add unimplemented methods: CTRL + I

Override methods: CTRL + O

Format code: CTRL + ALT + L

Show project: ALT + 1

Show logcat: ALT + 6

Hide project - logcat: SHIFT + ESC

Build: CTRL + F9

Build and Run: CTRL + F10

Alt+Shift+F10  access the Run/Debug dropdown on the main toolbar

Collapse all: CTRL + SHIFT + NumPad +

Expand all: CTRL + SHIFT + NumPad -


Editace: 2011-10-03 12:34:27
Počet článků v kategorii: 397
Url:file-open-read-to-stringbuilder-close-java-example
Share
Share
Tweet