How to Store a file (ex .mp3) into an array/arraylist?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1355 Views - Last Post: 11 May 2013 - 02:54 PM Rate Topic: -----

#1 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:16 PM

I have irrelevant code at the moment, so Im just asking anyone how they would go about storing files such as mp3 files into an array or arraylist that can later be put into a table. If anyone can help me answer this question it will be greatly appreciated.
Is This A Good Question/Topic? 0
  • +

Replies To: How to Store a file (ex .mp3) into an array/arraylist?

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:18 PM

What do you mean "put into a table?" You really shouldn't store Files in a database directly.
Was This Post Helpful? 0
  • +
  • -

#3 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:28 PM

Im working on a school project in which im building a media manager. I'm struggling figuring out how to import mp3 files into an array. Once i figure that out I want to store each file from the array into a table that I have created in the GUI/UserInterface
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:33 PM

Take a look of the File class.
Was This Post Helpful? 0
  • +
  • -

#5 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:36 PM

Would I make an arraylist of type String, or would I create a some sort of class that stores the mp3 information and make an arraylist of objects?
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:37 PM

Read my last post.
Was This Post Helpful? 0
  • +
  • -

#7 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:49 PM

What method from the File Class would I use to store the files into an array. I'm sorry for all the questions I'm just kind of a newbie when it comes to java :/
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:51 PM

This is the File object you store. Add this to the ArrayList.
File f = new File("somefile.mp3");


Was This Post Helpful? 0
  • +
  • -

#9 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:56 PM

Would the arrayList be of type String? Id want the arrayList to store the file itself not just the String of the file.mp3
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 01:56 PM

No. You would have an ArrayList<File>.
Was This Post Helpful? 0
  • +
  • -

#11 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 02:07 PM

Thank you! If I could trouble with one more question. Lets say I have a folder C:\Music that stores 10 or more mp3's and I want all those mp3s in the arrayList how would i read through the folder and copy all those files to the arraylist?
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 02:08 PM

Have you read the documentation in the File class? There are methods to get all the Files in the directory.
Was This Post Helpful? 0
  • +
  • -

#13 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 02:15 PM

I have read through the class and it has been helpful. I can now see if the files I want are there or not. Though I dont quite understand what methods are there that can be used to help me store all the files in that folder into an arraylist.
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 02:17 PM

The listFiles() method is useful. You'll have to still loop through the array yourself and add each element to the ArrayList.
Was This Post Helpful? 0
  • +
  • -

#15 ry3guy09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-April 12

Re: How to Store a file (ex .mp3) into an array/arraylist?

Posted 11 May 2013 - 02:23 PM

import java.io.*;
import java.util.*;

public class importMusic {
	public static void main(String[] args){
		
		
		File newMusic = new File("C:\\Music");
		ArrayList<File> musicArray = new ArrayList<>();
		
		for (int i = 0; i < 100; i++){
			musicArray.add(newMusic.listFiles(i));
		}	
	}
}


So that is what I have so far, obviously it is incorrect. I just can't wrap my head around where Im going wrong. Ive never been stumped in Java like I have with this problem, for some reason I just cant understand the logic.

This post has been edited by macosxnerd101: 11 May 2013 - 02:24 PM
Reason for edit:: Post your code between code tags

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2