Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

commas in my CSV file data

807601Mar 11 2008 — edited Mar 12 2008
Hi everyone,

I am trying to create a csv file.

One field that I am trying to out put is the description and has commas, that is throwing my columns out of sync.

I have tries putting the charactor ' around the data but all it does is output that charactor in the data.

my code is this
	public File createFile(Vector downloadObject){

		Iterator iterator = downloadObject.iterator();

		String query ="";

		try {
			Format formatter2 = new SimpleDateFormat("ddMMyyyy");

			String fileName="DELIVERY" + ".csv";

			File file = new File(fileName);

			StringBuffer output = new StringBuffer();

			while (iterator.hasNext()){

				
				VODownloadObject downloadObject2 = (VODownloadObject)iterator.next();
				
				query = 
					"'" +
					downloadObject2.getStrokeNumber().trim()
					+ "','"+ downloadObject2.getJdeIdNumber()
					+ "','"+ downloadObject2.getRollNumber()
					+ "','"+ downloadObject2.getSupplier()
					+ "',"+ ",'"+ downloadObject2.getQuality()
					+ "','"+ downloadObject2.getColour()
					+ "','"+ downloadObject2.getSupplierRollNumber()
					+ "',"+ ",'"+ downloadObject2.getDeliveryDate()
					+ "','"+ downloadObject2.getFabricComposition()
					+ "',"+ ","+ ",'"+ downloadObject2.getTicketLength()
					+ "','"+ downloadObject2.getTicketWidth()
					+ "',"+ ","+ ","+ ",";
					
				output.append(query + "\r\n");
				
			}
			
			BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
			out.write(output.toString());
			out.close();

			return file;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		
	}
the output is this.
'PA?????T','2/664659 ','153920','Menswear Formal, Shirts ',,'null','null',' ',,'11/07/2006','null',,,'-330000',' ',

in the "'Menswear Formal, Shirts " field, this is one field but it is splitting up into 2 fields because there is a comma after Formal. Anyone know how I can keep this as one field but with a comma in it?

thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2008
Added on Mar 11 2008
6 comments
1,523 views