这假设是一个简单的问题;不要在堆栈溢出中作为问题发布!
关注此文:How to: Create Embedded Resources
Form1.vb
来测试Visual Studio 2017社区版。testfile.WAV
个文件作为测试资源。仍然无论我做什么,result.exe
文件都是如此之大并且反映了大testfile.wav
文件大小,并且在任何情况下都无法将wav文件视为链接资源在bin\Debug
文件夹中的单独文件中!
试图改变几乎所有地方;但没有成功!
我希望result.exe
文件夹中的testfile.wav
和bin\Debug
分别链接而不是嵌入。
对我来说很奇怪?这是VS或应用程序设置中的错误吗?
非常感谢你 赞赏任何提示
注意:我想要达到的目的是为我的应用创建不同的主题,用户可以在其中选择外观;我的努力在上述情况下突破。如果result.exe
在其中包含资源,那么public TcpClient(OnMessageReceived listener) {
mMessageListener = listener;
}
/**
* Sends the message entered by client to the server
*
* @param message text entered by client
*/
public void sendMessage(String message) {
if (mBufferOut != null && !mBufferOut.checkError()) {
mBufferOut.println(message);
mBufferOut.flush();
}
}
/**
* Close the connection and release the members
*/
public void stopClient() {
mRun = false;
if (mBufferOut != null) {
mBufferOut.flush();
mBufferOut.close();
}
mMessageListener = null;
mBufferIn = null;
mBufferOut = null;
mServerMessage = null;
}
public void run() {
mRun = true;
try {
//here you must put your computer's IP address.
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
Log.e("TCP Client", "C: Connecting...");
//create a socket to make the connection with the server
Socket socket = new Socket(serverAddr, SERVER_PORT);
try {
//sends the message to the server
mBufferOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
sendMessage("hi");
//receives the message which the server sends back
mBufferIn = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));
//in this while the client listens for the messages sent by the server
while (mRun) {
mServerMessage = mBufferIn.readLine();
System.out.println(mServerMessage);
if (mServerMessage != null && mMessageListener != null) {
//call the method messageReceived from MyActivity class
mMessageListener.messageReceived(mServerMessage);
}
}
Log.e("RESPONSE FROM SERVER", "S: Received Message: '" + mServerMessage + "'");
} catch (Exception e) {
Log.e("TCP", "S: Error", e);
} finally {
//the socket must be closed. It is not possible to reconnect to this socket
// after it is closed, which means a new socket instance has to be created.
}
} catch (Exception e) {
Log.e("TCP", "C: Error", e);
}
}
//Declare the interface. The method messageReceived(String message) will must be implemented in the MyActivity
//class at on asynckTask doInBackground
public interface OnMessageReceived {
public void messageReceived(String message);
}
以MB为单位结束是没有意义的!
答案 0 :(得分:0)
TL; DR:如果您想将它作为一个松散的文件,那么您需要将它作为一个松散的文件。资源总是嵌入在应用程序中。
如果您通过Project Properties > Resources
添加资源,那么它将始终嵌入您的应用程序中。
如果您希望将其作为松散文件,则只需通过Add Existing Item
将其导入项目,并将项目的Copy to Output Directory
属性设置为Copy Always
。然后通过例如:
Dim WavPath As String = Path.Combine(Application.StartupPath, "yourfile.wav")
Dim WavFile As Byte() = File.ReadAllBytes(WavPath)
Linked vs Embedded只会在设计时产生影响。链接的资源仍嵌入到您的应用程序中,但在设计时您可以编辑它们,并可以轻松添加或删除其他资源。
嵌入式资源即使在设计时也嵌入在.resx
文件中,要编辑此类资源,您必须将其导出或更改为链接资源。当您需要在多个项目中共享相同的资源时,通常会使用嵌入式资源。然后将资源嵌入.resx
文件中,这样您只需要复制该文件而不是每个包含的文件。