Month: July 2017
Array to CSV in Java
package com.demo;
import java.io.IOException;
import com.csvreader.CsvWriter;
public class ArrayToCSVDemo {
public static void main(String[] args) {
String array[] = {"Suryanagar, Vikhroli", "Java", "SQL", "13"};
try {
CsvWriter writer = new CsvWriter("awesomefile.csv");
writer.writeRecord(array);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Reference Link: http://www.journaldev.com/12014/opencsv-csvreader-csvwriter-example
Jar File: http://www.java2s.com/Code/Jar/j/Downloadjavacsvjar.htm
Using FileWriter class
import java.io.FileWriter;
public class TestFileWriter {
public static String implodeString(String[] split) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
sb.append(split[i]);
if (i != split.length - 1) {
sb.append("\",\"");
}
}
return "\"" . concat(sb.toString()) .concat("\"");
}
public static void main(String[] args) {
String array[] = {"Suryanagar, Vikhroli", "Java", "SQL", "13"};
try {
FileWriter fw = new FileWriter("testout.csv");
//fw.write("\"Suryanagar, Vikhroli\", Java, SQL, 13");
fw.write(implodeString(array));
fw.close();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Success...");
}
}
Hello World django
Here are simple steps to create hello world web application in python using django framework
- Step 1: Install virtual environment and create virtual environment for your project
pip install virtualenvwrapper-win
mkvirtualenv myproject
-
pip install virtualenv -
virtualenv name_to_your_env -
name_to_your_env\Scripts\activate -
After activation $ django-admin.py startproject HelloWorld$ cd HelloWorld$ ls HelloWorld manage.py -
$ python manage.py runserver Validating models... 0 errors found ... Django version 1.6.5, using settings 'HelloWorld.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. - $ django-admin startapp HelloWorldApp
$ ls
HelloWorld HelloWorldApp manage.py - edit settings.py under HelloWorld project directory
# Application definition
INSTALLED_APPS = ( ‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘HelloWorldApp’, ) - modify the urls.py which is under the project directory, HelloWorld
from django.conf.urls import patterns, include, url from HelloWorldApp.views import foo #from django.contrib import admin #admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'HelloWorld.views.home', name='home'), # url(r'^blog/', include('blog.urls')), #url(r'^admin/', include(admin.site.urls)), url(r'HelloWorldApp/$', foo), ) - modify views.py under app directory, HelloWorldApp
# Create your views here. from django.http import HttpResponse def foo(request): return HttpResponse("Hello World!") - Run the server
python manage.py runserver
- Hit this URL on browser
http://localhost:8000/HelloWorldApp/
Ref Links:
- https://docs.djangoproject.com/en/1.11/howto/windows/
- http://www.bogotobogo.com/python/Django/Python_Django_hello_world.php
- https://stackoverflow.com/questions/18684231/python-setup-command-not-found
- https://stackoverflow.com/questions/8074955/cannot-import-name-patterns
- https://scotch.io/tutorials/build-your-first-python-and-django-application
- http://jinja.pocoo.org/docs/2.10/templates/
Installation
git clone https://github.com/angular/quickstart.git quickstart