Here you can find the source of getResourceContent(Object object, String resource)
Parameter | Description |
---|---|
resource | a parameter |
public static String getResourceContent(Object object, String resource)
//package com.java2s; /*//from ww w .ja v a2s . c o m This file is part of the Xapagy Cognitive Architecture Copyright (C) 2008-2017 Ladislau Boloni This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; public class Main { /** * Returns the name of the resource file in the form of a string * * @param resource * @return */ public static String getResourceContent(Object object, String resource) { URL testURL = object.getClass().getResource(resource); String testFile = null; try { testFile = new URI(testURL.toString()).getPath(); } catch (URISyntaxException e) { e.printStackTrace(); // should not normally happen } File file = new File(testFile); if (!file.exists()) { throw new Error("File: " + testFile + " does not exist"); } return testFile; } }